From c9d96eb9afa9a9fd35f50a971d2e43e455f5d769 Mon Sep 17 00:00:00 2001 From: Marcell Mars Date: Sat, 30 Jan 2021 02:07:16 +0100 Subject: [PATCH] backlinks generated not just as links but also as intersect in between front matter and sandpointsnamegraph --- data/sandpointsnamegraph.json | 33 +++++++++++++++++---------------- layouts/partials/scratch.html | 32 +++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/data/sandpointsnamegraph.json b/data/sandpointsnamegraph.json index 9c04c66..f9cb5d6 100644 --- a/data/sandpointsnamegraph.json +++ b/data/sandpointsnamegraph.json @@ -1,18 +1,19 @@ { - "syllabus": "syllabi", - "curriculum": "curriculums", - "notebook": "notebooks", - "book": "books", - "journal": "journals", - "topic": "topics", - "part": "parts", - "issue": "issues", - "tab": "tabs", - "experiment": "experiments", - "session": "sessions", - "chapter": "chapters", - "article": "articles", - "note": "notes", - "annex": "annexes", - "author": "authors" + "syllabus": "syllabi", + "curriculum": "curriculums", + "notebook": "notebooks", + "book": "books", + "journal": "journals", + "topic": "topics", + "part": "parts", + "issue": "issues", + "tab": "tabs", + "experiment": "experiments", + "session": "sessions", + "chapter": "chapters", + "article": "articles", + "note": "notes", + "annex": "annexes", + "author": "authors", + "editor": "editors" } diff --git a/layouts/partials/scratch.html b/layouts/partials/scratch.html index beb3b0e..2543e91 100644 --- a/layouts/partials/scratch.html +++ b/layouts/partials/scratch.html @@ -3,6 +3,14 @@ {{ $_ := newScratch }} {{ $debug := (slice) }} +{{ $sandnameSingular := (slice) }} +{{ $sandnamePlural := (slice) }} + +{{ range $k, $v := $.Site.Data.sandpointsnamegraph }} + {{ $sandnameSingular = $sandnameSingular | append $k }} + {{ $sandnamePlural = $sandnamePlural | append $v }} +{{ end }} + {{ $pPath := "" }} {{ range $p := .Site.RegularPages }} {{ $pPath = printf "/%s" $p.File }} @@ -23,16 +31,22 @@ {{ end }} {{ end }} - {{ with $authors := $p.Params.authors }} - {{ range $author := $authors }} - {{ $authorLink := printf "/author/%s" $author }} - {{ with ($_.Get $authorLink) }} - {{ $_.SetInMap $authorLink "backlinks" (uniq ((index ($_.Get $authorLink) "backlinks") | append $p)) }} + {{ $paramsKeys := (slice) }} + {{ range $k, $v := $p.Params }} + {{ $paramsKeys = $paramsKeys | append $k }} + {{ end }} + + {{ $mentions := intersect $paramsKeys $sandnamePlural }} + {{ range $mention := $mentions }} + {{ range $m := index $p.Params $mention }} + {{ $mentionLink := printf "/%s/%s" (substr $mention 0 -1) $m }} + {{ with ($_.Get $mentionLink) }} + {{ $_.SetInMap $mentionLink "backlinks" (uniq ((index ($_.Get $mentionLink) "backlinks") | append $p)) }} {{ else }} - {{ $_.SetInMap $authorLink "backlinks" (slice $p) }} - {{ end }} - {{ end }} - {{ end }} + {{ $_.SetInMap $mentionLink "backlinks" (slice $p) }} + {{ end }} + {{ end }} + {{ end }} {{ $gp := $.GetPage $pPath }} {{ $gpPath := printf "/%s" $gp.File }}