-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,12 @@ import ( | |
| "errors" | ||
| "fmt" | ||
| "goblog/blog" | ||
| "html" | ||
| "log" | ||
| "net/url" | ||
| "sort" | ||
| "strconv" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
|
|
@@ -115,12 +119,13 @@ func (p *ScholarPlugin) RenderPage(ctx *gplugin.HookContext, pageType string) (s | |
| return "", nil | ||
| } | ||
|
|
||
| data := gin.H{"has_plugin_content": true} | ||
|
|
||
| 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.", | ||
| } | ||
| data["plugin_content"] = `<div class="alert alert-warning" role="alert">Google Scholar ID not configured. Set it in the Scholar plugin settings.</div>` | ||
| return "page_content.html", data | ||
| } | ||
|
|
||
| limitStr := settings["article_limit"] | ||
|
|
@@ -132,18 +137,71 @@ 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() | ||
| data["plugin_content"] = `<div class="alert alert-danger" role="alert">` + html.EscapeString(err.Error()) + `</div>` | ||
| return "page_content.html", data | ||
| } | ||
|
|
||
| sortArticlesByDateDesc(articles) | ||
| p.sch.SaveCache(settings["profile_cache"], settings["article_cache"]) | ||
|
|
||
| data["plugin_content"] = renderArticlesHTML(articles) | ||
| return "page_content.html", data | ||
| } | ||
|
|
||
| // safeHref returns the URL only if it uses http or https scheme, otherwise empty. | ||
| func safeHref(rawURL string) string { | ||
| u, err := url.Parse(rawURL) | ||
| if err != nil { | ||
| return "" | ||
| } | ||
| if u.Scheme != "http" && u.Scheme != "https" { | ||
| return "" | ||
| } | ||
| return html.EscapeString(rawURL) | ||
| } | ||
|
|
||
| // renderArticlesHTML generates the HTML for the articles list. | ||
| func renderArticlesHTML(articles []*scholarlib.Article) string { | ||
| if len(articles) == 0 { | ||
| return `<p>No publications found.</p>` | ||
| } | ||
|
|
||
| return "page_research.html", data | ||
| var b strings.Builder | ||
| for _, a := range articles { | ||
| b.WriteString(`<div style="margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid #eee;">`) | ||
|
|
||
| // Title — link only if URL is safe | ||
| href := safeHref(a.ScholarURL) | ||
| if href != "" { | ||
| b.WriteString(`<div><a href="` + href + `">` + html.EscapeString(a.Title) + `</a></div>`) | ||
| } else { | ||
| b.WriteString(`<div>` + html.EscapeString(a.Title) + `</div>`) | ||
| } | ||
|
|
||
| if a.Authors != "" { | ||
| b.WriteString(`<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. |
||
|
|
||
| // Meta line: year · journal · citations | ||
| var meta []string | ||
| if a.Year > 0 { | ||
| meta = append(meta, strconv.Itoa(a.Year)) | ||
| } | ||
| if a.Journal != "" { | ||
| meta = append(meta, html.EscapeString(a.Journal)) | ||
| } | ||
| if a.NumCitations > 0 { | ||
| meta = append(meta, strconv.Itoa(a.NumCitations)+" citations") | ||
| } | ||
| if len(meta) > 0 { | ||
| b.WriteString(`<div style="color: #888; font-size: 13px;">` + strings.Join(meta, " · ") + `</div>`) | ||
| } | ||
|
|
||
| b.WriteString(`</div>`) | ||
| } | ||
| return b.String() | ||
| } | ||
|
|
||
| func (p *ScholarPlugin) ScheduledJobs() []gplugin.ScheduledJob { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.