Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions plugins/scholar/scholar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"errors"
"fmt"
"goblog/blog"
"html"
"log"
"sort"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -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>`,
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c81c85c.

}

Expand All @@ -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>`,
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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),
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 != "" {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 += ` &middot; ` + html.EscapeString(a.Journal)
}
if a.NumCitations > 0 {
out += ` &middot; ` + strconv.Itoa(a.NumCitations) + ` citations`
}
out += `</div>`
out += `</div>`
}
return out
}

func (p *ScholarPlugin) ScheduledJobs() []gplugin.ScheduledJob {
Expand Down
19 changes: 11 additions & 8 deletions themes/default/templates/page_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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" .}}
30 changes: 0 additions & 30 deletions themes/default/templates/page_research.html

This file was deleted.

25 changes: 0 additions & 25 deletions themes/default/templates/research.html

This file was deleted.

19 changes: 11 additions & 8 deletions themes/forest/templates/page_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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" .}}
24 changes: 0 additions & 24 deletions themes/forest/templates/page_research.html

This file was deleted.

19 changes: 11 additions & 8 deletions themes/minimal/templates/page_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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" .}}
24 changes: 0 additions & 24 deletions themes/minimal/templates/page_research.html

This file was deleted.

Loading