mirror of
https://codeberg.org/gothub/gothub
synced 2024-12-06 19:16:24 +01:00
add support for page content and number of pages
This commit is contained in:
+6
-1
@@ -1,6 +1,7 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"codeberg.org/gothub/gothub/utils"
|
||||
"github.com/gocolly/colly"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"log"
|
||||
@@ -61,7 +62,7 @@ func WikiView(c *fiber.Ctx) error {
|
||||
Scrape.LastEditor = re.ReplaceAllString(strings.Replace(e.ChildText("div.gh-header-meta"), "\n", "", -1), "${1}")
|
||||
Scrape.RevisionNum = strings.TrimSuffix(e.ChildText("a.Link--muted"), " revisions")
|
||||
})
|
||||
sc.OnHTML("div.Box--condensed", func(e *colly.HTMLElement) {
|
||||
sc.OnHTML("div.wiki-pages-box div.Box--condensed", func(e *colly.HTMLElement) {
|
||||
Scrape.PageNum = e.ChildText("span.Counter--primary")
|
||||
e.ForEach("ul.list-style-none li.Box-row", func(i int, el *colly.HTMLElement) {
|
||||
Scrape.Sidebar = append(Scrape.Sidebar, Sidebar{
|
||||
@@ -70,6 +71,10 @@ func WikiView(c *fiber.Ctx) error {
|
||||
})
|
||||
})
|
||||
})
|
||||
sc.OnHTML("div#wiki-body > div.markdown-body", func(e *colly.HTMLElement) {
|
||||
Content, _ := e.DOM.Html()
|
||||
Scrape.PageContent = string(utils.UGCPolicy().SanitizeBytes([]byte(Content)))
|
||||
})
|
||||
sc.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/wiki/" + c.Params("page"))
|
||||
// Add scrape-based info to wikiArray
|
||||
wikiArray = append(wikiArray, Scrape)
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
<p>LastEdit: {{.LastEdit}}</p>
|
||||
<p>LastEditor: {{.LastEditor}}</p>
|
||||
<p>RevisionNum: {{.RevisionNum}}</p>
|
||||
<p>PageNum: {{.PageNum}}</p>
|
||||
<p>Sidebar: {{.Sidebar}}</p>
|
||||
<p>Content:</p>
|
||||
{{ unescape .PageContent }}
|
||||
{{ end }} {{ else }}
|
||||
<h2>Wiki not found</h2>
|
||||
<p>That wiki doesn't exist.</p>
|
||||
|
||||
Reference in New Issue
Block a user