title support throught the garden (#33)

This commit is contained in:
Utsob Roy 2023-01-06 19:30:50 +06:00 committed by GitHub
parent c71685ce57
commit 7939b70509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 10 deletions

View File

@ -45,7 +45,7 @@ function getBacklinks(data) {
let preview = noteContent.slice(0, 240);
backlinks.push({
url: otherNote.url,
title: otherNote.data.page.fileSlug,
title: otherNote.data.title || otherNote.data.page.fileSlug,
preview,
id: counter++
})
@ -90,7 +90,7 @@ function getOutboundLinks(data, isHome=false){
uniqueLinks.add(outboundNote.url);
return {
url: outboundNote.url,
title: outboundNote.data.page.fileSlug,
title: outboundNote.data.title || outboundNote.data.page.fileSlug,
id: counter++,
};
} else {

View File

@ -31,14 +31,18 @@ module.exports = async () => {
return orderedTree;
}
function getPermalink(path) {
function getPermalinkAndName(path) {
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
}
@ -52,8 +56,9 @@ function populateWithPermalink(tree) {
const isNote = tree[key].path.endsWith(".md");
tree[key].isNote = isNote;
if (isNote) {
tree[key].permalink = getPermalink(tree[key].path);
tree[key].name = key.replace(".md", "");
let { permalink, name } = getPermalinkAndName(tree[key].path);
tree[key].permalink = permalink
tree[key].name = name
}
} else {
tree[key].isFolder = true;

View File

@ -1,11 +1,11 @@
---
title: "/{{ page.fileSlug }}/"
title: "/{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}/"
permalink: "notes/{{ page.fileSlug | slugify }}/"
---
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{ page.fileSlug }}</title>
<title>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</title>
{%include "components/pageheader.njk"%}
</head>
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section">
@ -23,7 +23,7 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
<div class="content cm-s-obsidian">
{% if settings.dgShowInlineTitle === true %}
<h1>{{ page.fileSlug }}</h1>
<h1>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</h1>
{% endif %}
{{ content | link | highlight | safe}}
</div>

View File

@ -33,7 +33,7 @@ module.exports = {
noteTitle: (data) => {
const currentnote = data.collections.gardenEntry && data.collections.gardenEntry[0];
if (currentnote && currentnote.data) {
return currentnote.data.page.fileSlug;
return currentNote.data.title || currentnote.data.page.fileSlug;
}
return "";
},

View File

@ -5,7 +5,7 @@ eleventyExcludeFromCollections: true
---
[{% for post in collections.note %}
{
"title": {{post.fileSlug | jsonify | safe }},
"title": {% if post.data.title %}{{post.data.title | jsonify | safe }}{% else %}{{post.fileSlug | jsonify | safe }}{% endif %},
"date":"{{ post.date }}",
"url":"{{ post.url }}",
"content": {{ post.templateContent | striptags(true) | link | jsonify | safe }}