-
Notifications
You must be signed in to change notification settings - Fork 7
Plugin pages render through generic content template #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,10 @@ import ( | |
| "errors" | ||
| "fmt" | ||
| "goblog/blog" | ||
| "html" | ||
| "log" | ||
| "sort" | ||
| "strconv" | ||
| "sync" | ||
| "time" | ||
|
|
||
|
|
@@ -118,8 +120,8 @@ func (p *ScholarPlugin) RenderPage(ctx *gplugin.HookContext, pageType string) (s | |
| settings := ctx.Settings | ||
| scholarID := settings["scholar_id"] | ||
| if scholarID == "" { | ||
| return "page_research.html", gin.H{ | ||
| "errors": "Google Scholar ID not configured. Set it in the Scholar plugin settings.", | ||
| return "page_content.html", gin.H{ | ||
| "plugin_content": `<div class="alert alert-warning">Google Scholar ID not configured. Set it in the Scholar plugin settings.</div>`, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -132,18 +134,44 @@ func (p *ScholarPlugin) RenderPage(ctx *gplugin.HookContext, pageType string) (s | |
| p.ensureScholar(settings) | ||
|
|
||
| articles, err := p.sch.QueryProfileWithMemoryCache(scholarID, limit) | ||
| data := gin.H{} | ||
| if err == nil { | ||
| sortArticlesByDateDesc(articles) | ||
| p.sch.SaveCache(settings["profile_cache"], settings["article_cache"]) | ||
| data["articles"] = articles | ||
| } else { | ||
| if err != nil { | ||
| log.Printf("Scholar query failed: %v", err) | ||
| data["articles"] = make([]*scholarlib.Article, 0) | ||
| data["errors"] = err.Error() | ||
| return "page_content.html", gin.H{ | ||
| "plugin_content": `<div class="alert alert-danger">` + html.EscapeString(err.Error()) + `</div>`, | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c81c85c. |
||
| } | ||
|
|
||
| return "page_research.html", data | ||
| sortArticlesByDateDesc(articles) | ||
| p.sch.SaveCache(settings["profile_cache"], settings["article_cache"]) | ||
|
|
||
| return "page_content.html", gin.H{ | ||
| "plugin_content": renderArticlesHTML(articles), | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c81c85c. |
||
| } | ||
|
|
||
| // renderArticlesHTML generates the HTML for the articles list. | ||
| func renderArticlesHTML(articles []*scholarlib.Article) string { | ||
| out := "" | ||
| for _, a := range articles { | ||
|
Comment on lines
+165
to
+172
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c81c85c. |
||
| out += `<div style="margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid #eee;">` | ||
| out += `<div><a href="` + html.EscapeString(a.ScholarURL) + `">` + html.EscapeString(a.Title) + `</a></div>` | ||
| if a.Authors != "" { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c81c85c. |
||
| out += `<div style="color: #666; font-size: 13px;">` + html.EscapeString(a.Authors) + `</div>` | ||
| } | ||
|
Comment on lines
+166
to
+185
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c81c85c. |
||
| out += `<div style="color: #888; font-size: 13px;">` | ||
| if a.Year > 0 { | ||
| out += strconv.Itoa(a.Year) | ||
| } | ||
| if a.Journal != "" { | ||
| out += ` · ` + html.EscapeString(a.Journal) | ||
| } | ||
| if a.NumCitations > 0 { | ||
| out += ` · ` + strconv.Itoa(a.NumCitations) + ` citations` | ||
| } | ||
| out += `</div>` | ||
| out += `</div>` | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func (p *ScholarPlugin) ScheduledJobs() []gplugin.ScheduledJob { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,15 +21,18 @@ <h1>{{ .page.Title }}</h1> | |
| {{ if .is_admin }} | ||
| <p class="text-left"><a href="/admin/pages/{{ .page.ID }}">Edit this page</a></p> | ||
| {{ end }} | ||
| {{ if .plugin_content }} | ||
| <div id="page-content">{{ .plugin_content | rawHTML }}</div> | ||
| {{ else }} | ||
| <div id="page-content"></div> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js" integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA==" crossorigin="anonymous"></script> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c81c85c. |
||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.7/purify.min.js" integrity="sha512-78KH17QLT5e55GJqP76vutp1D2iAoy06WcYBXB6iBCsmO6wWzx0Qdg8EDpm8mKXv68BcvHOyeeP4wxAL0twJGQ==" crossorigin="anonymous"></script> | ||
| <script> | ||
| var converter = new showdown.Converter({tables: true}); | ||
| var content = {{ .page.Content }}; | ||
| document.getElementById('page-content').innerHTML = DOMPurify.sanitize(converter.makeHtml(content)); | ||
| </script> | ||
| {{ end }} | ||
| </div> | ||
|
|
||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js" integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA==" crossorigin="anonymous"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.7/purify.min.js" integrity="sha512-78KH17QLT5e55GJqP76vutp1D2iAoy06WcYBXB6iBCsmO6wWzx0Qdg8EDpm8mKXv68BcvHOyeeP4wxAL0twJGQ==" crossorigin="anonymous"></script> | ||
| <script> | ||
| var converter = new showdown.Converter({tables: true}); | ||
| var content = {{ .page.Content }}; | ||
| document.getElementById('page-content').innerHTML = DOMPurify.sanitize(converter.makeHtml(content)); | ||
| </script> | ||
|
|
||
| {{ template "footer.html" .}} | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,18 @@ <h1>{{ .page.Title }}</h1> | |
| {{ if .is_admin }} | ||
| <p class="text-left"><a href="/admin/pages/{{ .page.ID }}">Edit this page</a></p> | ||
| {{ end }} | ||
| {{ if .plugin_content }} | ||
| <div id="page-content">{{ .plugin_content | rawHTML }}</div> | ||
| {{ else }} | ||
| <div id="page-content"></div> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js" integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA==" crossorigin="anonymous"></script> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c81c85c. |
||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.7/purify.min.js" integrity="sha512-78KH17QLT5e55GJqP76vutp1D2iAoy06WcYBXB6iBCsmO6wWzx0Qdg8EDpm8mKXv68BcvHOyeeP4wxAL0twJGQ==" crossorigin="anonymous"></script> | ||
| <script> | ||
| var converter = new showdown.Converter({tables: true}); | ||
| var content = {{ .page.Content }}; | ||
| document.getElementById('page-content').innerHTML = DOMPurify.sanitize(converter.makeHtml(content)); | ||
| </script> | ||
| {{ end }} | ||
| </div></div> | ||
|
|
||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js" integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA==" crossorigin="anonymous"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.7/purify.min.js" integrity="sha512-78KH17QLT5e55GJqP76vutp1D2iAoy06WcYBXB6iBCsmO6wWzx0Qdg8EDpm8mKXv68BcvHOyeeP4wxAL0twJGQ==" crossorigin="anonymous"></script> | ||
| <script> | ||
| var converter = new showdown.Converter({tables: true}); | ||
| var content = {{ .page.Content }}; | ||
| document.getElementById('page-content').innerHTML = DOMPurify.sanitize(converter.makeHtml(content)); | ||
| </script> | ||
|
|
||
| {{ template "footer.html" .}} | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,18 @@ <h1>{{ .page.Title }}</h1> | |
| {{ if .is_admin }} | ||
| <p class="text-left"><a href="/admin/pages/{{ .page.ID }}">Edit this page</a></p> | ||
| {{ end }} | ||
| {{ if .plugin_content }} | ||
| <div id="page-content">{{ .plugin_content | rawHTML }}</div> | ||
| {{ else }} | ||
| <div id="page-content"></div> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js" integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA==" crossorigin="anonymous"></script> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c81c85c. |
||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.7/purify.min.js" integrity="sha512-78KH17QLT5e55GJqP76vutp1D2iAoy06WcYBXB6iBCsmO6wWzx0Qdg8EDpm8mKXv68BcvHOyeeP4wxAL0twJGQ==" crossorigin="anonymous"></script> | ||
| <script> | ||
| var converter = new showdown.Converter({tables: true}); | ||
| var content = {{ .page.Content }}; | ||
| document.getElementById('page-content').innerHTML = DOMPurify.sanitize(converter.makeHtml(content)); | ||
| </script> | ||
| {{ end }} | ||
| </div> | ||
|
|
||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js" integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA==" crossorigin="anonymous"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.7/purify.min.js" integrity="sha512-78KH17QLT5e55GJqP76vutp1D2iAoy06WcYBXB6iBCsmO6wWzx0Qdg8EDpm8mKXv68BcvHOyeeP4wxAL0twJGQ==" crossorigin="anonymous"></script> | ||
| <script> | ||
| var converter = new showdown.Converter({tables: true}); | ||
| var content = {{ .page.Content }}; | ||
| document.getElementById('page-content').innerHTML = DOMPurify.sanitize(converter.makeHtml(content)); | ||
| </script> | ||
|
|
||
| {{ template "footer.html" .}} | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c81c85c.