Skip to content

Commit

Permalink
Merge branch 'uroybd-maturity-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Eskild Steensen committed Feb 14, 2023
2 parents 92b9998 + 42b7d23 commit 54dcc4f
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 82 deletions.
6 changes: 5 additions & 1 deletion .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ module.exports = function (eleventyConfig) {
}

let permalink = `/notes/${slugify(fileName)}`;
let noteIcon = process.env.NOTE_ICON_DEFAULT;
const title = linkTitle ? linkTitle : fileName;
let deadLink = false;

Expand All @@ -175,13 +176,16 @@ module.exports = function (eleventyConfig) {
if (frontMatter.data.permalink) {
permalink = frontMatter.data.permalink;
}
if (frontMatter.data.noteIcon) {
noteIcon = frontMatter.data.noteIcon;
}
} catch {
deadLink = true;
}

return `<a class="internal-link ${
deadLink ? "is-unresolved" : ""
}" href="${permalink}${headerLinkPath}">${title}</a>`;
}" ${deadLink ? "" : 'data-note-icon="' + noteIcon + '"'} href="${permalink}${headerLinkPath}">${title}</a>`;
})
);
});
Expand Down
6 changes: 5 additions & 1 deletion plugin-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"filesToAdd": [
"src/site/styles/custom-style.scss",
".env",
"src/site/favicon.svg"
"src/site/favicon.svg",
"src/site/img/default-note-icon.svg",
"src/site/img/tree-1.svg",
"src/site/img/tree-2.svg",
"src/site/img/tree-3.svg"
],
"filesToModify": [
".eleventy.js",
Expand Down
127 changes: 67 additions & 60 deletions src/site/_data/filetree.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,87 @@
const fsFileTree = require("fs-file-tree");
const matter = require('gray-matter');
const fs = require('fs');
const matter = require("gray-matter");
const fs = require("fs");

module.exports = async () => {
const tree = await fsFileTree("src/site/notes");
populateWithPermalink(tree);
const tree = await fsFileTree("src/site/notes");
populateWithPermalink(tree);

return sortTree(tree);
}
return sortTree(tree);
};

const sortTree = (unsorted) => {
//Sort by folder before file, then by name
const orderedTree = Object.keys(unsorted).sort((a, b) => {
if (a.indexOf(".md") > -1 && b.indexOf(".md") === -1) {
return 1;
}
//Sort by folder before file, then by name
const orderedTree = Object.keys(unsorted)
.sort((a, b) => {
if (a.indexOf(".md") > -1 && b.indexOf(".md") === -1) {
return 1;
}

if (a.indexOf(".md") === -1 && b.indexOf(".md") > -1) {
return -1;
}
if (a.indexOf(".md") === -1 && b.indexOf(".md") > -1) {
return -1;
}

if (a.toLowerCase() > b.toLowerCase()) {
return 1;
}
if (a.toLowerCase() > b.toLowerCase()) {
return 1;
}

return -1;
}).reduce(
(obj, key) => {
obj[key] = unsorted[key];
return -1;
})
.reduce((obj, key) => {
obj[key] = unsorted[key];

return obj;
},
{}
);
return obj;
}, {});

for (const key of Object.keys(orderedTree)) {
if (!orderedTree[key].path) {
orderedTree[key] = sortTree(orderedTree[key])
}
for (const key of Object.keys(orderedTree)) {
if (!orderedTree[key].path) {
orderedTree[key] = sortTree(orderedTree[key]);
}
}

return orderedTree;
}
return orderedTree;
};

function getPermalinkAndName(path, key) {
let permalink = "/"
let name = key.replace(".md", "");
try {
const file = fs.readFileSync(`${path}`, 'utf8');
const frontMatter = matter(file);
if (frontMatter.data.permalink) {
permalink = frontMatter.data.permalink;
}
if (frontMatter.data.title) {
name = frontMatter.data.title
}
} catch {
//ignore
function getPermalinkMeta(path, key) {
let permalink = "/";
let name = key.replace(".md", "");
let noteIcon = process.env.NOTE_ICON_DEFAULT;
try {
const file = fs.readFileSync(`${path}`, "utf8");
const frontMatter = matter(file);
if (frontMatter.data.permalink) {
permalink = frontMatter.data.permalink;
}
if (frontMatter.data.title) {
name = frontMatter.data.title;
}
if (frontMatter.data.noteIcon) {
noteIcon = frontMatter.data.noteIcon;
}
} catch {
//ignore
}

return { permalink, name };
return { permalink, name, noteIcon };
}

function populateWithPermalink(tree) {
Object.keys(tree).forEach(key => {
if (tree[key].path) {
const isNote = tree[key].path.endsWith(".md");
tree[key].isNote = isNote;
if (isNote) {
let { permalink, name } = getPermalinkAndName(tree[key].path, key);
tree[key].permalink = permalink
tree[key].name = name
}
} else {
tree[key].isFolder = true;
populateWithPermalink(tree[key]);
}
});
Object.keys(tree).forEach((key) => {
if (tree[key].path) {
const isNote = tree[key].path.endsWith(".md");
tree[key].isNote = isNote;
if (isNote) {
let { permalink, name, noteIcon } = getPermalinkMeta(
tree[key].path,
key
);
tree[key].permalink = permalink;
tree[key].name = name;
tree[key].noteIcon = noteIcon;
}
} else {
tree[key].isFolder = true;
populateWithPermalink(tree[key]);
}
});
}
27 changes: 27 additions & 0 deletions src/site/_data/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,37 @@ module.exports = async () => {
if (themeStyle) {
themeStyle = themeStyle.split("site")[1];
}
let bodyClasses = [];
let noteIconsSettings = {
filetree: false,
links: false,
title: false,
default: process.env.NOTE_ICON_DEFAULT,
};
if (process.env.NOTE_ICON_TITLE && process.env.NOTE_ICON_TITLE == "true") {
bodyClasses.push("title-note-icon");
noteIconsSettings.title = true;
}
if (
process.env.NOTE_ICON_FILETREE &&
process.env.NOTE_ICON_FILETREE == "true"
) {
bodyClasses.push("filetree-note-icon");
noteIconsSettings.filetree = true;
}
if (
process.env.NOTE_ICON_INTERNAL_LINKS &&
process.env.NOTE_ICON_INTERNAL_LINKS == "true"
) {
bodyClasses.push("links-note-icon");
noteIconsSettings.links = true;
}
const meta = {
env: process.env.ELEVENTY_ENV,
theme: process.env.THEME,
themeStyle,
bodyClasses: bodyClasses.join(" "),
noteIconsSettings,
baseTheme: process.env.BASE_THEME || "dark",
siteName: process.env.SITE_NAME_HEADER || "Digital Garden",
siteBaseUrl: baseUrl,
Expand Down
4 changes: 2 additions & 2 deletions src/site/_includes/components/filetree.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div x-show="isOpen" style="display:none" class="{{'filelist' if step>0}}">
{%if fileOrFolder.isNote %}
<div @click.stop class="notelink {{ 'active-note' if fileOrFolder.permalink === permalink}}">
<i class="fa fa-sticky-note" aria-hidden="true"></i>
<a style="text-decoration: none;" class="filename" href="{{fileOrFolder.permalink}}">{{fileOrFolder.name}} </a>
{%- if not meta.noteIconsSettings.filetree -%}<i class="fa fa-sticky-note" aria-hidden="true"></i>{%- endif -%}
<a data-note-icon="{{fileOrFolder.noteIcon}}" style="text-decoration: none;" class="filename" href="{{fileOrFolder.permalink}}">{{fileOrFolder.name}} </a>
</div>
{% elif fileOrFolder.isFolder%}
<div class="folder inner-folder" x-data="{isOpen: $persist(false).as('{{currentPath}}')}" @click.stop="isOpen=!isOpen">
Expand Down
4 changes: 2 additions & 2 deletions src/site/_includes/layouts/note.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
{% include imp %}
{% endfor %}
</head>
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section">
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section {{meta.bodyClasses}}">
{%include "components/notegrowthhistory.njk"%}

{% if settings.dgShowFileTree !== true %}
Expand All @@ -29,7 +29,7 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
<main class="content cm-s-obsidian">
<header>
{% if settings.dgShowInlineTitle === true %}
<h1>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</h1>
<h1 data-note-icon="{% if noteIcon %}{{noteIcon}}{% else %}{{meta.noteIconsSettings.default}}{% endif %}">{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</h1>
{% endif %}
<div class="header-meta">
{% if settings.dgShowTags === true and tags %}
Expand Down
8 changes: 8 additions & 0 deletions src/site/img/default-note-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/site/img/tree-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/site/img/tree-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/site/img/tree-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/site/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% include imp %}
{% endfor %}
</head>
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section">
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section {{meta.bodyClasses}}">
{%include "components/notegrowthhistory.njk"%}
{% if settings.dgShowFileTree !== true %}
{%include "components/navbar.njk"%}
Expand Down
40 changes: 38 additions & 2 deletions src/site/styles/digital-garden-base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

body {
overflow-x: hidden;
--note-icon-1: url(/img/tree-1.svg);
--note-icon-2: url(/img/tree-2.svg);
--note-icon-3: url(/img/tree-3.svg);
--note-icon-fallback: url(/img/default-note-icon.svg);
}

.content {
Expand Down Expand Up @@ -95,7 +99,7 @@ ul.task-list {
height: 100%;
}

#graph-controls{
#graph-controls {
margin-top: 10px;
}

Expand Down Expand Up @@ -378,7 +382,8 @@ ul.task-list {
padding: 3px 0 3px 10px;
}

.filelist {
.filename {
margin-left: 5px;
}

.notelink.active-note {
Expand Down Expand Up @@ -661,3 +666,34 @@ input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
margin-top: -10px;
}

body.title-note-icon .cm-s-obsidian > header > h1[data-note-icon]::before,
body.filetree-note-icon .filename[data-note-icon]::before,
body.links-note-icon .internal-link[data-note-icon]::before {
content: " ";
display: inline-block;
width: 0.9em;
height: 1em;
background-size: contain;
background-repeat: no-repeat;
background-position: bottom;
background-image: var(--note-icon-fallback);
}

body.title-note-icon .cm-s-obsidian > header > h1[data-note-icon="1"]::before,
body.filetree-note-icon .filename[data-note-icon="1"]::before,
body.links-note-icon .internal-link[data-note-icon="1"]::before {
background-image: var(--note-icon-1);
}

body.title-note-icon .cm-s-obsidian > header > h1[data-note-icon="2"]::before,
body.filetree-note-icon .filename[data-note-icon="2"]::before,
body.links-note-icon .internal-link[data-note-icon="2"]::before {
background-image: var(--note-icon-2);
}

body.title-note-icon .cm-s-obsidian > header > h1[data-note-icon="3"]::before,
body.filetree-note-icon .filename[data-note-icon="3"]::before,
body.links-note-icon .internal-link[data-note-icon="3"]::before {
background-image: var(--note-icon-3);
}
Loading

0 comments on commit 54dcc4f

Please sign in to comment.