From 0b9dc5c2a6056c484f8f0a563124128fc153641c Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sat, 20 Aug 2022 23:06:31 +0500 Subject: [PATCH] Rename: Leave redirection field off by default if there are no backlinks --- backlinks/backlinks.go | 6 +++--- backlinks/web.go | 2 +- hypview/hypview.go | 32 ++++++++++++++++++++------------ hypview/nav.qtpl | 2 +- hypview/nav.qtpl.go | 2 +- hypview/view_rename.html | 4 ++-- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/backlinks/backlinks.go b/backlinks/backlinks.go index 605d8bd..3660580 100644 --- a/backlinks/backlinks.go +++ b/backlinks/backlinks.go @@ -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 diff --git a/backlinks/web.go b/backlinks/web.go index 62c5498..ff5cb75 100644 --- a/backlinks/web.go +++ b/backlinks/web.go @@ -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()) } } diff --git a/hypview/hypview.go b/hypview/hypview.go index d284c37..f8304a2 100644 --- a/hypview/hypview.go +++ b/hypview/hypview.go @@ -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"}}Переименовывайте аккуратно. Документация на английском.{{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, }, diff --git a/hypview/nav.qtpl b/hypview/nav.qtpl index 1591ace..ba48b15 100644 --- a/hypview/nav.qtpl +++ b/hypview/nav.qtpl @@ -22,7 +22,7 @@ {% code u := meta.U lc := meta.Lc - backs := backlinks.BacklinksCount(h) + backs := backlinks.BacklinksCount(h.CanonicalName()) %}