Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const {
} = require("./src/helpers/userSetup");

const Image = require("@11ty/eleventy-img");
const { sortNotes } = require("./src/helpers/collections");

function transformImage(src, cls, alt, sizes, widths = ["500", "700", "auto"]) {
let options = {
widths: widths,
Expand All @@ -25,7 +23,7 @@ function transformImage(src, cls, alt, sizes, widths = ["500", "700", "auto"]) {
urlPath: "/img/optimized",
};

// generate images, while this is async we don't wait
// generate images, while this is async we dont wait
Image(src, options);
let metadata = Image.statsSync(src, options);
return metadata;
Expand Down Expand Up @@ -561,9 +559,6 @@ module.exports = function (eleventyConfig) {
},
});

// Add sorted notes collection
eleventyConfig.addCollection("notes", sortNotes);

userEleventySetup(eleventyConfig);

return {
Expand Down
30 changes: 5 additions & 25 deletions src/helpers/filetreeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const sortTree = (unsorted) => {
//Sort by folder before file, then by name
const orderedTree = Object.keys(unsorted)
.sort((a, b) => {

let a_pinned = unsorted[a].pinned || false;
let b_pinned = unsorted[b].pinned || false;
if (a_pinned != b_pinned) {
Expand All @@ -23,19 +24,6 @@ const sortTree = (unsorted) => {
return -1;
}

// If both are notes and they're in Daily Notes folder, sort by creation date (newest first)
if (a_is_note && b_is_note) {
const a_path = unsorted[a].path || "";
const b_path = unsorted[b].path || "";
if (a_path.includes("Daily Notes") && b_path.includes("Daily Notes")) {
const a_created = unsorted[a].created;
const b_created = unsorted[b].created;
if (a_created && b_created) {
return new Date(b_created) - new Date(a_created);
}
}
}

//Regular expression that extracts any initial decimal number
const aNum = parseFloat(a.match(/^\d+(\.\d+)?/));
const bNum = parseFloat(b.match(/^\d+(\.\d+)?/));
Expand All @@ -55,6 +43,7 @@ const sortTree = (unsorted) => {
})
.reduce((obj, key) => {
obj[key] = unsorted[key];

return obj;
}, {});

Expand All @@ -75,9 +64,6 @@ function getPermalinkMeta(note, key) {
let hide = false;
let pinned = false;
let folders = null;
let created = null;
let updated = null;
let path = "";
try {
if (note.data.permalink) {
permalink = note.data.permalink;
Expand All @@ -91,33 +77,27 @@ function getPermalinkMeta(note, key) {
if (note.data.noteIcon) {
noteIcon = note.data.noteIcon;
}
// Reason for adding the hide flag instead of removing completely from file tree is to
// allow users to use the filetree data elsewhere without the fear of losing any data.
if (note.data.hide) {
hide = note.data.hide;
}
if (note.data.pinned) {
pinned = note.data.pinned;
}
if (note.data.created) {
created = note.data.created;
}
if (note.data.updated) {
updated = note.data.updated;
}
if (note.data["dg-path"]) {
folders = note.data["dg-path"].split("/");
path = note.data["dg-path"];
} else {
folders = note.filePathStem
.split("notes/")[1]
.split("/");
path = folders.join("/");
}
folders[folders.length - 1]+= ".md";
} catch {
//ignore
}

return [{ permalink, name, noteIcon, hide, pinned, created, updated, path }, folders];
return [{ permalink, name, noteIcon, hide, pinned }, folders];
}

function assignNested(obj, keyPath, value) {
Expand Down
2 changes: 1 addition & 1 deletion src/site/_includes/layouts/note.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
permalink: "notes/{{ page.fileSlug | slugify }}/"
---
<!DOCTYPE html>
<html lang="{{ meta.mainLanguage }}">
Expand Down Expand Up @@ -67,7 +68,6 @@
{% include imp %}
{% endfor %}
{{ content | hideDataview | taggify | link | safe}}
{% include "components/dailyNoteNav.njk" %}
{% for imp in dynamics.common.afterContent %}
{% include imp %}
{% endfor %}
Expand Down
7 changes: 1 addition & 6 deletions src/site/notes/notes.11tydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ module.exports = {
if (data.tags.indexOf("gardenEntry") != -1) {
return "/";
}
// If a permalink is explicitly set in the frontmatter, use it
if (data.permalink) {
return data.permalink;
}
// Otherwise, generate a permalink from the file path
return `/notes/${data.filePathStem}`;
return data.permalink || undefined;
},
settings: (data) => {
const noteSettings = {};
Expand Down