mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 03:36:16 +00:00
Rename: Leave redirection field off by default if there are no backlinks
This commit is contained in:
parent
482a81975c
commit
0b9dc5c2a6
@ -53,9 +53,9 @@ func IndexBacklinks() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BacklinksCount returns the amount of backlinks to the hypha.
|
// BacklinksCount returns the amount of backlinks to the hypha. Pass canonical names.
|
||||||
func BacklinksCount(h hyphae.Hypha) int {
|
func BacklinksCount(hyphaName string) int {
|
||||||
if links, exists := backlinkIndex[h.CanonicalName()]; exists {
|
if links, exists := backlinkIndex[hyphaName]; exists {
|
||||||
return len(links)
|
return len(links)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
@ -32,7 +32,7 @@ func handlerBacklinks(w http.ResponseWriter, rq *http.Request) {
|
|||||||
func handlerOrphans(w http.ResponseWriter, rq *http.Request) {
|
func handlerOrphans(w http.ResponseWriter, rq *http.Request) {
|
||||||
var orphans []string
|
var orphans []string
|
||||||
for h := range hyphae.YieldExistingHyphae() {
|
for h := range hyphae.YieldExistingHyphae() {
|
||||||
if BacklinksCount(h) == 0 {
|
if BacklinksCount(h.CanonicalName()) == 0 {
|
||||||
orphans = append(orphans, h.CanonicalName())
|
orphans = append(orphans, h.CanonicalName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package hypview
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/backlinks"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
@ -69,7 +70,7 @@ var (
|
|||||||
{{define "new name"}}Новое название:{{end}}
|
{{define "new name"}}Новое название:{{end}}
|
||||||
{{define "rename recursively"}}Также переименовать подгифы{{end}}
|
{{define "rename recursively"}}Также переименовать подгифы{{end}}
|
||||||
{{define "rename tip"}}Переименовывайте аккуратно. <a href="/help/en/rename">Документация на английском.</a>{{end}}
|
{{define "rename tip"}}Переименовывайте аккуратно. <a href="/help/en/rename">Документация на английском.</a>{{end}}
|
||||||
{{define "leave redirections"}}Оставить перенаправления{{end}}
|
{{define "leave redirection"}}Оставить перенаправление{{end}}
|
||||||
`
|
`
|
||||||
chainNaviTitle viewutil.Chain
|
chainNaviTitle viewutil.Chain
|
||||||
chainEditHypha viewutil.Chain
|
chainEditHypha viewutil.Chain
|
||||||
@ -109,22 +110,29 @@ func EditHypha(meta viewutil.Meta, hyphaName string, isNew bool, content string,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type deleteRenameData struct {
|
type renameData struct {
|
||||||
|
*viewutil.BaseData
|
||||||
|
HyphaName string
|
||||||
|
LeaveRedirectionDefault bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func RenameHypha(meta viewutil.Meta, hyphaName string) {
|
||||||
|
viewutil.ExecutePage(meta, chainRenameHypha, renameData{
|
||||||
|
BaseData: &viewutil.BaseData{
|
||||||
|
Addr: "/rename/" + hyphaName,
|
||||||
|
},
|
||||||
|
HyphaName: hyphaName,
|
||||||
|
LeaveRedirectionDefault: backlinks.BacklinksCount(hyphaName) != 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type deleteData struct {
|
||||||
*viewutil.BaseData
|
*viewutil.BaseData
|
||||||
HyphaName string
|
HyphaName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenameHypha(meta viewutil.Meta, hyphaName string) {
|
|
||||||
viewutil.ExecutePage(meta, chainRenameHypha, deleteRenameData{
|
|
||||||
BaseData: &viewutil.BaseData{
|
|
||||||
Addr: "/rename/" + hyphaName,
|
|
||||||
},
|
|
||||||
HyphaName: hyphaName,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeleteHypha(meta viewutil.Meta, hyphaName string) {
|
func DeleteHypha(meta viewutil.Meta, hyphaName string) {
|
||||||
viewutil.ExecutePage(meta, chainDeleteHypha, deleteRenameData{
|
viewutil.ExecutePage(meta, chainDeleteHypha, deleteData{
|
||||||
BaseData: &viewutil.BaseData{
|
BaseData: &viewutil.BaseData{
|
||||||
Addr: "/delete/" + hyphaName,
|
Addr: "/delete/" + hyphaName,
|
||||||
},
|
},
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
{% code
|
{% code
|
||||||
u := meta.U
|
u := meta.U
|
||||||
lc := meta.Lc
|
lc := meta.Lc
|
||||||
backs := backlinks.BacklinksCount(h)
|
backs := backlinks.BacklinksCount(h.CanonicalName())
|
||||||
%}
|
%}
|
||||||
<nav class="hypha-info">
|
<nav class="hypha-info">
|
||||||
<ul class="hypha-info__list">
|
<ul class="hypha-info__list">
|
||||||
|
@ -130,7 +130,7 @@ func streamhyphaInfo(qw422016 *qt422016.Writer, meta viewutil.Meta, h hyphae.Hyp
|
|||||||
//line hypview/nav.qtpl:23
|
//line hypview/nav.qtpl:23
|
||||||
u := meta.U
|
u := meta.U
|
||||||
lc := meta.Lc
|
lc := meta.Lc
|
||||||
backs := backlinks.BacklinksCount(h)
|
backs := backlinks.BacklinksCount(h.CanonicalName())
|
||||||
|
|
||||||
//line hypview/nav.qtpl:26
|
//line hypview/nav.qtpl:26
|
||||||
qw422016.N().S(`
|
qw422016.N().S(`
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
<input type="checkbox" id="recursive" name="recursive" value="true" checked/>
|
<input type="checkbox" id="recursive" name="recursive" value="true" checked/>
|
||||||
<label for="recursive">{{block "rename recursively" .}}Rename subhyphae too{{end}}</label>
|
<label for="recursive">{{block "rename recursively" .}}Rename subhyphae too{{end}}</label>
|
||||||
<br>
|
<br>
|
||||||
<input type="checkbox" id="redirection" name="redirection" value="true" checked/>
|
<input type="checkbox" id="redirection" name="redirection" value="true" {{if .LeaveRedirectionDefault}}checked{{end}}/>
|
||||||
<label for="redirection">{{block "leave redirections" .}}Leave redirections{{end}}</label>
|
<label for="redirection">{{block "leave redirection" .}}Leave redirection{{end}}</label>
|
||||||
|
|
||||||
<p>{{block "rename tip" .}}Rename carefully. <a href="/help/en/rename">Documentation.</a>{{end}}</p>
|
<p>{{block "rename tip" .}}Rename carefully. <a href="/help/en/rename">Documentation.</a>{{end}}</p>
|
||||||
<button type="submit" value="Confirm" class="btn">
|
<button type="submit" value="Confirm" class="btn">
|
||||||
|
Loading…
Reference in New Issue
Block a user