mirror of
https://codeberg.org/gothub/gothub
synced 2024-12-06 19:16:24 +01:00
pinned gists + prettier
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"codeberg.org/gothub/gothub/utils"
|
||||
"github.com/gocolly/colly"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type TopicMeta struct {
|
||||
Name string
|
||||
Desc string
|
||||
ImageLink string
|
||||
CreatedBy string
|
||||
Released string
|
||||
Followers string
|
||||
Company string
|
||||
Links []string
|
||||
Related []string
|
||||
Language []string
|
||||
Sort string
|
||||
}
|
||||
|
||||
type TopicStuff struct {
|
||||
FullName string
|
||||
Desc string
|
||||
Stars string
|
||||
Language string
|
||||
OtherTags []string
|
||||
LastUpdate []string
|
||||
ImageLink string
|
||||
}
|
||||
|
||||
func HandleTopics(c *fiber.Ctx) error {
|
||||
var topicMetaArray []TopicMeta
|
||||
var topicStuffArray []TopicStuff
|
||||
// Scraping
|
||||
UserAgent, ok := os.LookupEnv("GOTHUB_USER_AGENT")
|
||||
if !ok {
|
||||
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
|
||||
}
|
||||
|
||||
sc := colly.NewCollector(colly.AllowedDomains("github.com"), colly.UserAgent(UserAgent))
|
||||
sc.OnHTML("div.border h1", func(e *colly.HTMLElement) {
|
||||
topicMetaArray.FullName = e.Text
|
||||
}
|
||||
sc.OnHTML("div.p-4.mb-5", func(e *colly.HTMLElement) {
|
||||
topicMetaArray.Desc = e.ChildText("div.markdown-body p")
|
||||
topicMetaArray.Image = strings.TrimPrefix(e.ChildAttr("div.ml-sm-4 img", "src"), "https://raw.githubusercontent.com/")
|
||||
})
|
||||
sc.OnHTML("div.col-md-4", func(e *colly.HTMLElement) {
|
||||
e.ForEach("p", func(i int, el *colly.HTMLElement) {
|
||||
if e.ChildText("span") == "Created by" {
|
||||
topicMetaArray.CreatedBy = strings.TrimPrefix(e.Text, "Created by")
|
||||
} else if e.ChildText("span") == "Released" {
|
||||
topicMetaArray.Released = strings.TrimPrefix(e.Text, "Released")
|
||||
}
|
||||
})
|
||||
e.ForEach("dl dd", func(i int, el *colly.HTMLElement) {
|
||||
if e.ChildAttr("svg", "aria-label") == "Topic followers" {
|
||||
topicMetaArray.Followers = e.Text
|
||||
} else if e.ChildText("svg.octicon-organization") {
|
||||
topicMetaArray.Company = e.ChildText("span")
|
||||
} else if e.ChildText("svg.octicon-link") {
|
||||
topicMetaArray.Link = append(topicMetaArray.Link, el.ChildAttr("a", "href"))
|
||||
}
|
||||
})
|
||||
e.ForEach("a.topic-tag", func(i int, el *colly.HTMLElement) {
|
||||
topicMetaArray.Related = append(topicMetaArray.Related, e.Text)
|
||||
})
|
||||
})
|
||||
sc.OnHTML("div.js-details-container div.Details-content--hidden-not-important", func(e *colly.HTMLElement) {
|
||||
e.ForEach("div.js-navigation-item", func(i int, el *colly.HTMLElement) {
|
||||
var FileType string
|
||||
if el.ChildAttr("div.flex-shrink-0 svg", "aria-label") == "Directory" {
|
||||
FileType = "dir"
|
||||
} else {
|
||||
FileType = "file"
|
||||
}
|
||||
repoFilesArray = append(repoFilesArray, RepoFiles{
|
||||
Name: el.ChildText("div.flex-auto span.d-block a.js-navigation-open"),
|
||||
Path: el.ChildText("div.flex-auto span.d-block a.js-navigation-open"),
|
||||
Type: FileType,
|
||||
Fullname: topicMetaArray.Fullname,
|
||||
DefaultBranch: topicMetaArray.DefaultBranch,
|
||||
})
|
||||
})
|
||||
})
|
||||
sc.Visit("https://github.com/topics/" + c.Params("topic"))
|
||||
return c.Render("repo", fiber.Map{
|
||||
"title": "Topic " + topicMetaArray.Name,
|
||||
"topicMeta": topicMetaArray,
|
||||
"topicStuff": topicStuffArray,
|
||||
})
|
||||
}
|
||||
+18
-2
@@ -40,6 +40,7 @@ type User struct {
|
||||
type RepoList struct {
|
||||
Name string
|
||||
Type string
|
||||
Link string
|
||||
Desc string
|
||||
Lang string
|
||||
Stars string
|
||||
@@ -154,15 +155,30 @@ func HandleUser(c *fiber.Ctx) error {
|
||||
var MainRepo RepoList
|
||||
MainRepo = RepoList{} // Clear data if old data is present
|
||||
MainRepo.Name = strings.TrimPrefix(el.ChildAttr("div.width-full a", "href"), "/")
|
||||
MainRepo.Type = el.ChildText("div.width-full span.Label")
|
||||
MainRepo.Link = el.ChildAttr("div.width-full a", "href")
|
||||
if strings.Contains(MainRepo.Name, "https://gist.github.com/") {
|
||||
MainRepo.Name = el.ChildAttr("div.width-full a span", "title")
|
||||
MainRepo.Link = "/gist" + strings.TrimPrefix(el.ChildAttr("div.width-full a", "href"), "https://gist.github.com")
|
||||
}
|
||||
if strings.Contains(MainRepo.Link, "/gist") {
|
||||
MainRepo.Type = "Gist"
|
||||
} else {
|
||||
MainRepo.Type = "Repository"
|
||||
}
|
||||
MainRepo.Desc = el.ChildText("p.pinned-item-desc")
|
||||
if MainRepo.Type == "Gist" {
|
||||
MainRepo.Desc = ""
|
||||
el.ForEach("div.rounded-bottom-2 div.flex-items-center", func(in int, ele *colly.HTMLElement) {
|
||||
MainRepo.Desc = MainRepo.Desc + "\n" + ele.ChildText("pre")
|
||||
})
|
||||
}
|
||||
MainRepo.Lang = el.ChildText("p.color-fg-muted span[itemprop*='programmingLanguage']")
|
||||
MainRepo.Stars = el.ChildText("p.color-fg-muted a[href*='/stargazers' i]")
|
||||
MainRepo.Forks = el.ChildText("p.color-fg-muted a[href*='/forks' i]")
|
||||
MainRepo.ForkOf = el.ChildText("p.text-small a.Link--muted")
|
||||
Scrape.MainRepos = append(Scrape.MainRepos, MainRepo)
|
||||
})
|
||||
Scrape.PinOrPopular = e.ChildText("h2.text-normal")
|
||||
Scrape.PinOrPopular = strings.TrimSuffix(e.ChildText("h2.text-normal"), " repositories")
|
||||
})
|
||||
sc.Visit("https://github.com/" + c.Params("user") + "/")
|
||||
// Fixing the output a bit
|
||||
|
||||
+7
-7
@@ -22,14 +22,14 @@
|
||||
{{end}} {{ if .files}}
|
||||
<div class="user-readme">
|
||||
{{ range $key, $value := .files}}
|
||||
<p><a id="{{.Name}}" href="#{{.Name}}">{{.Name}}</a></p>
|
||||
<p><a id="{{.Name}}" href="#{{.Name}}">{{.Name}}</a></p>
|
||||
<style>
|
||||
// prettier-ignore
|
||||
{{.Css}}
|
||||
pre {
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
// prettier-ignore
|
||||
{{.Css}}
|
||||
pre {
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
</style>
|
||||
{{.File}} {{ end }}
|
||||
</div>
|
||||
|
||||
+23
-13
@@ -3,19 +3,26 @@
|
||||
<main>
|
||||
<h2>GotHub is an alternative front-end for GitHub.</h2>
|
||||
{{ if not .setupstatus }}
|
||||
<div class="setup-notice">
|
||||
<b>GotHub is not set up!</b> Please look at <a href="https://codeberg.org/gothub/gothub/issues/92">this issue</a> to see how to set up GotHub, or set the GOTHUB_SETUP_COMPLETE environment variable to true to suppress this message. If you are a user of this instance, please contact the instance maintainer.
|
||||
</div>
|
||||
<div class="setup-notice">
|
||||
<b>GotHub is not set up!</b> Please look at
|
||||
<a href="https://codeberg.org/gothub/gothub/issues/92">this issue</a> to see
|
||||
how to set up GotHub, or set the GOTHUB_SETUP_COMPLETE environment variable
|
||||
to true to suppress this message. If you are a user of this instance, please
|
||||
contact the instance maintainer.
|
||||
</div>
|
||||
{{ end}}
|
||||
<h3>Features</h3>
|
||||
<ul>
|
||||
<li>Lightweight - for both you and the instance host</li>
|
||||
<li>No JavaScript - pure HTML and CSS awesomeness</li>
|
||||
<li>
|
||||
No requests made to GitHub from the client side - they won't even know you made a request!
|
||||
No requests made to GitHub from the client side - they won't even know you
|
||||
made a request!
|
||||
</li>
|
||||
<li>Open source - for peer review & trustworthiness</li>
|
||||
<li>Save bandwidth - no JavaScript, tracking bloat or extra fonts loaded.</li>
|
||||
<li>
|
||||
Save bandwidth - no JavaScript, tracking bloat or extra fonts loaded.
|
||||
</li>
|
||||
</ul>
|
||||
<h3>Privacy</h3>
|
||||
<p>
|
||||
@@ -24,15 +31,16 @@
|
||||
href="https://docs.github.com/en/site-policy/privacy-policies/github-privacy-statement"
|
||||
target="_blank"
|
||||
>If you care, you can read GitHub's privacy policy here</a
|
||||
> <a href="https://tosdr.org/en/service/297" target="_blank"
|
||||
>(TOS;DR)</a
|
||||
>. GotHub solves this by proxying all GitHub requests for you!
|
||||
>
|
||||
<a href="https://tosdr.org/en/service/297" target="_blank">(TOS;DR)</a>.
|
||||
GotHub solves this by proxying all GitHub requests for you!
|
||||
</p>
|
||||
<h3>Usage</h3>
|
||||
<p>
|
||||
Just replace <code class="index-gh">github.com</code> with
|
||||
<code class="index-gh">{{.host}}</code> or <code class="index-gh">gist.github.com</code>
|
||||
with <code class="index-gh">{{.host}}/gist</code>!
|
||||
<code class="index-gh">{{.host}}</code> or
|
||||
<code class="index-gh">gist.github.com</code> with
|
||||
<code class="index-gh">{{.host}}/gist</code>!
|
||||
</p>
|
||||
<h3>DMCA/Copyright Notice</h3>
|
||||
<p>
|
||||
@@ -53,9 +61,11 @@
|
||||
yourself private from them instead.</i
|
||||
>
|
||||
<h3>Credits</h3>
|
||||
<a href="https://midou.dev">Midou36O</a> - desigining the GotHub logo<br>
|
||||
<a href="https://odyssey346.dev">Odyssey346</a> - majority of the code, <b>main</b>tainer<br>
|
||||
<a href="https://arya.projectsegfau.lt">Arya</a> - code contributions and second maintainer<br>
|
||||
<a href="https://midou.dev">Midou36O</a> - desigining the GotHub logo<br />
|
||||
<a href="https://odyssey346.dev">Odyssey346</a> - majority of the code,
|
||||
<b>main</b>tainer<br />
|
||||
<a href="https://arya.projectsegfau.lt">Arya</a> - code contributions and
|
||||
second maintainer<br />
|
||||
<h3>Info</h3>
|
||||
{{ if eq .version "unknown, please build with Go 1.13+ or use Git"}} GotHub
|
||||
version: <code>unknown</code> {{ else }} GotHub version:
|
||||
|
||||
+14
-7
@@ -73,15 +73,22 @@
|
||||
</div>
|
||||
{{ end }} {{ if .MainRepos }}
|
||||
<div class="user-readme">
|
||||
<h3>{{.PinOrPopular}} repositories</h2>
|
||||
<h3>{{.PinOrPopular}} repositories</h3>
|
||||
{{range .MainRepos}}
|
||||
<a class="user-repo-card" href="/{{.Name}}">
|
||||
<p class="user-repo-header">{{.Name}}</p>
|
||||
{{if .ForkOf}}
|
||||
Forked from: <a href="/{{.ForkOf}}">{{.ForkOf}}</a>
|
||||
{{else}} {{end}} {{if .Desc}}
|
||||
<a class="user-repo-card" href="{{.Link}}">
|
||||
<p class="user-repo-header">{{.Name}} ({{.Type}})</p>
|
||||
{{if .ForkOf}} Forked from: <a href="/{{.ForkOf}}">{{.ForkOf}}</a>
|
||||
{{else}} {{end}} {{if .Desc}} {{if eq .Type "Gist"}}
|
||||
<style>
|
||||
pre {
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
</style>
|
||||
<pre> {{.Desc}} </pre>
|
||||
{{else}}
|
||||
<p class="">{{.Desc}}</p>
|
||||
{{else}} {{end}}
|
||||
{{end}} {{else}} {{end}}
|
||||
<p class="">
|
||||
{{if .Stars}}⭐ {{.Stars}}{{else}}{{end}} {{if .Forks}} 🍴 {{.Forks}}
|
||||
{{else}}{{end}} {{if .Lang}} 🗒️ {{.Lang}} {{else}}{{end}}
|
||||
|
||||
Reference in New Issue
Block a user