diff --git a/src/site/_includes/components/graphScript.njk b/src/site/_includes/components/graphScript.njk new file mode 100644 index 0000000..9b4dd68 --- /dev/null +++ b/src/site/_includes/components/graphScript.njk @@ -0,0 +1,117 @@ + \ No newline at end of file diff --git a/src/site/_includes/components/pageheader.njk b/src/site/_includes/components/pageheader.njk index 7acab75..28f6581 100644 --- a/src/site/_includes/components/pageheader.njk +++ b/src/site/_includes/components/pageheader.njk @@ -7,7 +7,14 @@ + + + + + + + diff --git a/src/site/_includes/components/sidebar.njk b/src/site/_includes/components/sidebar.njk new file mode 100644 index 0000000..d06f1f4 --- /dev/null +++ b/src/site/_includes/components/sidebar.njk @@ -0,0 +1,68 @@ +
+ + + + {%if dgShowLocalGraph === true %} + {%include "components/graphScript.njk"%} + {% endif %} + + \ No newline at end of file diff --git a/src/site/_includes/layouts/note.njk b/src/site/_includes/layouts/note.njk index f900ede..61e5dc0 100644 --- a/src/site/_includes/layouts/note.njk +++ b/src/site/_includes/layouts/note.njk @@ -16,6 +16,10 @@ permalink: "notes/{{ page.fileSlug | slugify }}/" 🏡 Back Home {% endif %} {{ content | link | highlight | safe}} + + {% if dgShowBacklinks === true or dgShowLocalGraph === true%} + {%include "components/sidebar.njk"%} + {% endif %}
diff --git a/src/site/index.11tydata.js b/src/site/index.11tydata.js new file mode 100644 index 0000000..8f3616b --- /dev/null +++ b/src/site/index.11tydata.js @@ -0,0 +1,101 @@ + +const wikilink = /\[\[(.*?\|.*?)\]\]/g + +function caselessCompare(a, b) { + return a.toLowerCase() === b.toLowerCase(); +} + +module.exports = { + eleventyComputed: { + backlinks: (data) => { + const notes = data.collections.note; + if(!notes){ + return []; + } + const currentFileSlug = data.page.filePathStem.replace('/notes/', ''); + + let backlinks = []; + let counter = 1; + + for (const otherNote of notes) { + const noteContent = otherNote.template.frontMatter.content; + + const outboundLinks = (noteContent.match(wikilink) || []).map(link => ( + link.slice(2, -2) + .split("|")[0] + .replace(/.(md|markdown)\s?$/i, "") + .trim() + )); + + if (outboundLinks.some(link => caselessCompare(link, currentFileSlug))) { + + let preview = noteContent.slice(0, 240); + backlinks.push({ + url: otherNote.url, + title: otherNote.data.page.fileSlug, + preview, + id: counter++ + }) + } + } + + return backlinks; + + }, + outbound: (data) => { + const notes = data.collections.note; + + if(!notes || notes.length == 0){ + return []; + } + + const currentNote = data.collections.gardenEntry && data.collections.gardenEntry[0]; + if(!currentNote){ + return []; + } + + + let counter = 1; + + const noteContent = currentNote.template.frontMatter.content; + + const outboundLinks = (noteContent.match(wikilink) || []).map(link => ( + link.slice(2, -2) + .split("|")[0] + .replace(/.(md|markdown)\s?$/i, "") + .trim() + )); + + let outbound = outboundLinks.map(fileslug => { + var outboundNote = notes.find(x => caselessCompare(x.data.page.filePathStem.replace("/notes/", ""), fileslug)); + if(!outboundNote){ + return null; + } + + return { + url: outboundNote.url, + title: outboundNote.data.page.fileSlug, + id: counter++ + } + }).filter(x=>x); + + return outbound; + + }, + dgShowLocalGraph: (data) => { + const currentNote = data.collections.gardenEntry && data.collections.gardenEntry[0]; + if(currentNote && currentNote.data && currentNote.data.dgShowLocalGraph){ + return true; + } + + return false; + }, + dgShowBacklinks: (data) =>{ + const currentnote = data.collections.gardenEntry && data.collections.gardenEntry[0]; + if(currentnote && currentnote.data && currentnote.data.dgShowLocalGraph){ + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/src/site/index.njk b/src/site/index.njk index 547209d..a56a9a6 100644 --- a/src/site/index.njk +++ b/src/site/index.njk @@ -7,9 +7,14 @@ {%include "components/notegrowthhistory.njk"%}
+ {%- for garden in collections.gardenEntry -%} {{garden.templateContent | link | highlight | safe }} {%- endfor -%} -
- - + + {%if collections.gardenEntry[0].data.dgShowBacklinks === true or collections.gardenEntry[0].data.dgShowLocalGraph === true%} + {%include "components/sidebar.njk" %} + {%endif%} + + + \ No newline at end of file diff --git a/src/site/notes/notes.11tydata.js b/src/site/notes/notes.11tydata.js new file mode 100644 index 0000000..c8adedd --- /dev/null +++ b/src/site/notes/notes.11tydata.js @@ -0,0 +1,86 @@ + +const wikilink = /\[\[(.*?\|.*?)\]\]/g + +function caselessCompare(a, b) { + return a.toLowerCase() === b.toLowerCase(); +} + +module.exports = { + eleventyComputed: { + backlinks: (data) => { + const notes = data.collections.note; + if(!notes){ + return []; + } + const currentFileSlug = data.page.filePathStem.replace('/notes/', ''); + + let backlinks = []; + let counter = 1; + + for (const otherNote of notes) { + const noteContent = otherNote.template.frontMatter.content; + + const outboundLinks = (noteContent.match(wikilink) || []).map(link => ( + link.slice(2, -2) + .split("|")[0] + .replace(/.(md|markdown)\s?$/i, "") + .trim() + )); + + if (outboundLinks.some(link => caselessCompare(link, currentFileSlug))) { + + let preview = noteContent.slice(0, 240); + backlinks.push({ + url: otherNote.url, + title: otherNote.data.page.fileSlug, + preview, + id: counter++ + }) + } + } + + return backlinks; + + }, + outbound: (data) => { + const notes = data.collections.note; + const currentFileSlug = data.page.filePathStem.replace('/notes/', ''); + + if(!notes || notes.length == 0){ + return []; + } + + const currentNote = notes.find(x =>x.data.page.filePathStem && caselessCompare(x.data.page.filePathStem.replace('/notes/', ''), currentFileSlug)); + if(!currentNote){ + return []; + } + + let counter = 1; + + const noteContent = currentNote.template.frontMatter.content; + + const outboundLinks = (noteContent.match(wikilink) || []).map(link => ( + link.slice(2, -2) + .split("|")[0] + .replace(/.(md|markdown)\s?$/i, "") + .trim() + )); + + let outbound = outboundLinks.map(fileslug => { + var outboundNote = notes.find(x => caselessCompare(x.data.page.filePathStem.replace("/notes/", ""), fileslug)); + if(!outboundNote){ + return null; + } + + return { + url: outboundNote.url, + title: outboundNote.data.page.fileSlug, + id: counter++ + } + }).filter(x=>x); + + return outbound; + + } + } +} \ No newline at end of file diff --git a/src/site/styles/digital-garden-base.scss b/src/site/styles/digital-garden-base.scss index 9420b12..263c8f3 100644 --- a/src/site/styles/digital-garden-base.scss +++ b/src/site/styles/digital-garden-base.scss @@ -60,6 +60,49 @@ ul.task-list { padding-left: 15px; } + +.sidebar { + position: fixed; + top: 50%; + transform: translateY(-50%); + right: 0; + height: 100%; + background-color: var(--background-secondary); + min-width: 25px; + display: flex; +} + +.expand-line { + display: flex; + flex-direction: column; + justify-content: center; +} + +.sidebar-container { + padding: 20px; + width: 100%; + overflow-y: auto; +} + +.backlink-card { + padding: 20px; + border-radius: 4px; + margin-bottom: 20px; + background-color: var(--background-primary); + width: 100%; + +} + +@media(max-width: 1100px) { + .sidebar { + position: relative; + transform: none; + border-radius: 4px; + } + +} + + div[class*="language-ad-"], div[class*="callout-"] { font-family: 'Roboto', sans-serif; @@ -410,4 +453,4 @@ div.callout-quote { div.language-ad-cite, div.callout-cite { background-color: rgba(158, 158, 158, .5) -} +} \ No newline at end of file diff --git a/src/site/styles/style.scss b/src/site/styles/style.scss index 9695368..bcee450 100644 --- a/src/site/styles/style.scss +++ b/src/site/styles/style.scss @@ -3,6 +3,14 @@ * MODIFY THE custom-style.scss FILE INSTEAD. ***/ + +body{ + --background-primary: rgb(32, 31, 31); + --background-secondary: rgb(57, 56, 56); + --text-normal: #dcddde; + --text-accent: rgb(97, 186, 245); +} + h1 { color: #FFEF60; } @@ -19,6 +27,12 @@ h4 { color: #72DCFF; } +button { + border: none; + color: white; + padding: 5px 15px; +} + .centered { position: absolute; top: 50%; @@ -28,8 +42,8 @@ h4 { } .theme-dark { - background: rgb(32, 31, 31); - color: white; + background: var(--background-primary); + color: var(--text-normal); font-family: 'Roboto', sans-serif; } @@ -44,7 +58,7 @@ a.is-unresolved{ } a { text-decoration: underline; - color: rgb(97, 186, 245); + color: var(--text-accent) } .font-bg {