add support for page content and number of pages

This commit is contained in:
Arya Kiran
2023-04-26 20:21:23 +05:30
parent 16fa0305bd
commit fa049697e7
2 changed files with 9 additions and 1 deletions
+6 -1
View File
@@ -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)
+3
View File
@@ -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>