1
0
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:
Timur Ismagilov 2022-08-20 23:06:31 +05:00
parent 482a81975c
commit 0b9dc5c2a6
6 changed files with 28 additions and 20 deletions

View File

@ -53,9 +53,9 @@ func IndexBacklinks() {
}
}
// BacklinksCount returns the amount of backlinks to the hypha.
func BacklinksCount(h hyphae.Hypha) int {
if links, exists := backlinkIndex[h.CanonicalName()]; exists {
// BacklinksCount returns the amount of backlinks to the hypha. Pass canonical names.
func BacklinksCount(hyphaName string) int {
if links, exists := backlinkIndex[hyphaName]; exists {
return len(links)
}
return 0

View File

@ -32,7 +32,7 @@ func handlerBacklinks(w http.ResponseWriter, rq *http.Request) {
func handlerOrphans(w http.ResponseWriter, rq *http.Request) {
var orphans []string
for h := range hyphae.YieldExistingHyphae() {
if BacklinksCount(h) == 0 {
if BacklinksCount(h.CanonicalName()) == 0 {
orphans = append(orphans, h.CanonicalName())
}
}

View File

@ -2,6 +2,7 @@ package hypview
import (
"embed"
"github.com/bouncepaw/mycorrhiza/backlinks"
"html/template"
"log"
"strings"
@ -69,7 +70,7 @@ var (
{{define "new name"}}Новое название:{{end}}
{{define "rename recursively"}}Также переименовать подгифы{{end}}
{{define "rename tip"}}Переименовывайте аккуратно. <a href="/help/en/rename">Документация на английском.</a>{{end}}
{{define "leave redirections"}}Оставить перенаправления{{end}}
{{define "leave redirection"}}Оставить перенаправление{{end}}
`
chainNaviTitle 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
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) {
viewutil.ExecutePage(meta, chainDeleteHypha, deleteRenameData{
viewutil.ExecutePage(meta, chainDeleteHypha, deleteData{
BaseData: &viewutil.BaseData{
Addr: "/delete/" + hyphaName,
},

View File

@ -22,7 +22,7 @@
{% code
u := meta.U
lc := meta.Lc
backs := backlinks.BacklinksCount(h)
backs := backlinks.BacklinksCount(h.CanonicalName())
%}
<nav class="hypha-info">
<ul class="hypha-info__list">

View File

@ -130,7 +130,7 @@ func streamhyphaInfo(qw422016 *qt422016.Writer, meta viewutil.Meta, h hyphae.Hyp
//line hypview/nav.qtpl:23
u := meta.U
lc := meta.Lc
backs := backlinks.BacklinksCount(h)
backs := backlinks.BacklinksCount(h.CanonicalName())
//line hypview/nav.qtpl:26
qw422016.N().S(`

View File

@ -13,8 +13,8 @@
<input type="checkbox" id="recursive" name="recursive" value="true" checked/>
<label for="recursive">{{block "rename recursively" .}}Rename subhyphae too{{end}}</label>
<br>
<input type="checkbox" id="redirection" name="redirection" value="true" checked/>
<label for="redirection">{{block "leave redirections" .}}Leave redirections{{end}}</label>
<input type="checkbox" id="redirection" name="redirection" value="true" {{if .LeaveRedirectionDefault}}checked{{end}}/>
<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>
<button type="submit" value="Confirm" class="btn">