mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-05-05 16:14:06 +00:00
Implement /orphans
This page lists hyphae which have no backlinks
This commit is contained in:
parent
ce6447fea4
commit
b2e504ec06
15
backlinks/view_orphans.html
Normal file
15
backlinks/view_orphans.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{{define "orphaned hyphae"}}Orphaned hyphae{{end}}
|
||||||
|
{{define "title"}}{{template "orphaned hyphae"}}{{end}}
|
||||||
|
{{define "body"}}
|
||||||
|
<main class="main-width">
|
||||||
|
<h1>{{template "orphaned hyphae"}}</h1>
|
||||||
|
<p>{{block "orphan description" .}}Hyphae which have no backlinks are listed here.{{end}}</p>
|
||||||
|
<ol>
|
||||||
|
{{range .Orphans}}
|
||||||
|
<li>
|
||||||
|
<a class="wikilink" href="/hypha/{{.}}">{{beautifulName .}}</a>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ol>
|
||||||
|
</main>
|
||||||
|
{{end}}
|
@ -3,19 +3,25 @@ package backlinks
|
|||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitHandlers(rtr *mux.Router) {
|
func InitHandlers(rtr *mux.Router) {
|
||||||
rtr.PathPrefix("/backlinks/").HandlerFunc(handlerBacklinks)
|
rtr.PathPrefix("/backlinks/").HandlerFunc(handlerBacklinks)
|
||||||
chain = viewutil.
|
rtr.PathPrefix("/orphans").HandlerFunc(handlerOrphans)
|
||||||
|
chainBacklinks = viewutil.
|
||||||
En(viewutil.CopyEnWith(fs, "view_backlinks.html")).
|
En(viewutil.CopyEnWith(fs, "view_backlinks.html")).
|
||||||
Ru(template.Must(viewutil.CopyRuWith(fs, "view_backlinks.html").Parse(ruTranslation)))
|
Ru(template.Must(viewutil.CopyRuWith(fs, "view_backlinks.html").Parse(ruTranslation)))
|
||||||
|
chainOrphans = viewutil.
|
||||||
|
En(viewutil.CopyEnWith(fs, "view_orphans.html")).
|
||||||
|
Ru(template.Must(viewutil.CopyRuWith(fs, "view_orphans.html").Parse(ruTranslation)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlerBacklinks lists all backlinks to a hypha.
|
// handlerBacklinks lists all backlinks to a hypha.
|
||||||
@ -30,6 +36,17 @@ func handlerBacklinks(w http.ResponseWriter, rq *http.Request) {
|
|||||||
viewBacklinks(viewutil.MetaFrom(w, rq), hyphaName, backlinks)
|
viewBacklinks(viewutil.MetaFrom(w, rq), hyphaName, backlinks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handlerOrphans(w http.ResponseWriter, rq *http.Request) {
|
||||||
|
var orphans []string
|
||||||
|
for h := range hyphae.YieldExistingHyphae() {
|
||||||
|
if BacklinksCount(h) == 0 {
|
||||||
|
orphans = append(orphans, h.CanonicalName())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(orphans)
|
||||||
|
viewOrphans(viewutil.MetaFrom(w, rq), orphans)
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed *.html
|
//go:embed *.html
|
||||||
fs embed.FS
|
fs embed.FS
|
||||||
@ -37,8 +54,11 @@ var (
|
|||||||
{{define "backlinks to text"}}Обратные ссылки на {{.}}{{end}}
|
{{define "backlinks to text"}}Обратные ссылки на {{.}}{{end}}
|
||||||
{{define "backlinks to link"}}Обратные ссылки на <a href="/hypha/{{.}}">{{beautifulName .}}</a>{{end}}
|
{{define "backlinks to link"}}Обратные ссылки на <a href="/hypha/{{.}}">{{beautifulName .}}</a>{{end}}
|
||||||
{{define "description"}}Ниже перечислены гифы, на которых есть ссылка на эту гифу, трансклюзия этой гифы или эта гифа вставлена как изображение.{{end}}
|
{{define "description"}}Ниже перечислены гифы, на которых есть ссылка на эту гифу, трансклюзия этой гифы или эта гифа вставлена как изображение.{{end}}
|
||||||
|
{{define "orphaned hyphae"}}Гифы-сироты{{end}}
|
||||||
|
{{define "orphan description"}}Ниже перечислены гифы без ссылок на них.{{end}}
|
||||||
`
|
`
|
||||||
chain viewutil.Chain
|
chainBacklinks viewutil.Chain
|
||||||
|
chainOrphans viewutil.Chain
|
||||||
)
|
)
|
||||||
|
|
||||||
type backlinksData struct {
|
type backlinksData struct {
|
||||||
@ -48,7 +68,7 @@ type backlinksData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func viewBacklinks(meta viewutil.Meta, hyphaName string, backlinks []string) {
|
func viewBacklinks(meta viewutil.Meta, hyphaName string, backlinks []string) {
|
||||||
if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", backlinksData{
|
if err := chainBacklinks.Get(meta).ExecuteTemplate(meta.W, "page", backlinksData{
|
||||||
BaseData: viewutil.BaseData{
|
BaseData: viewutil.BaseData{
|
||||||
Meta: meta,
|
Meta: meta,
|
||||||
Addr: "/backlinks/" + hyphaName,
|
Addr: "/backlinks/" + hyphaName,
|
||||||
@ -61,3 +81,22 @@ func viewBacklinks(meta viewutil.Meta, hyphaName string, backlinks []string) {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type orphansData struct {
|
||||||
|
viewutil.BaseData
|
||||||
|
Orphans []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func viewOrphans(meta viewutil.Meta, orphans []string) {
|
||||||
|
if err := chainOrphans.Get(meta).ExecuteTemplate(meta.W, "page", orphansData{
|
||||||
|
BaseData: viewutil.BaseData{
|
||||||
|
Meta: meta,
|
||||||
|
Addr: "/orphans",
|
||||||
|
HeaderLinks: cfg.HeaderLinks,
|
||||||
|
CommonScripts: cfg.CommonScripts,
|
||||||
|
},
|
||||||
|
Orphans: orphans,
|
||||||
|
}); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user