mirror of
https://github.com/tcsenpai/obsidiangarden_netlify.git
synced 2025-06-06 20:55:21 +00:00
title support throught the garden (#33)
This commit is contained in:
parent
c71685ce57
commit
7939b70509
@ -45,7 +45,7 @@ function getBacklinks(data) {
|
|||||||
let preview = noteContent.slice(0, 240);
|
let preview = noteContent.slice(0, 240);
|
||||||
backlinks.push({
|
backlinks.push({
|
||||||
url: otherNote.url,
|
url: otherNote.url,
|
||||||
title: otherNote.data.page.fileSlug,
|
title: otherNote.data.title || otherNote.data.page.fileSlug,
|
||||||
preview,
|
preview,
|
||||||
id: counter++
|
id: counter++
|
||||||
})
|
})
|
||||||
@ -90,7 +90,7 @@ function getOutboundLinks(data, isHome=false){
|
|||||||
uniqueLinks.add(outboundNote.url);
|
uniqueLinks.add(outboundNote.url);
|
||||||
return {
|
return {
|
||||||
url: outboundNote.url,
|
url: outboundNote.url,
|
||||||
title: outboundNote.data.page.fileSlug,
|
title: outboundNote.data.title || outboundNote.data.page.fileSlug,
|
||||||
id: counter++,
|
id: counter++,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,14 +31,18 @@ module.exports = async () => {
|
|||||||
return orderedTree;
|
return orderedTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPermalink(path) {
|
function getPermalinkAndName(path) {
|
||||||
let permalink = "/"
|
let permalink = "/"
|
||||||
|
let name = key.replace(".md", "");
|
||||||
try {
|
try {
|
||||||
const file = fs.readFileSync(`${path}`, 'utf8');
|
const file = fs.readFileSync(`${path}`, 'utf8');
|
||||||
const frontMatter = matter(file);
|
const frontMatter = matter(file);
|
||||||
if (frontMatter.data.permalink) {
|
if (frontMatter.data.permalink) {
|
||||||
permalink = frontMatter.data.permalink;
|
permalink = frontMatter.data.permalink;
|
||||||
}
|
}
|
||||||
|
if (frontMatter.data.title){
|
||||||
|
name = frontMatter.data.title
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
@ -52,8 +56,9 @@ function populateWithPermalink(tree) {
|
|||||||
const isNote = tree[key].path.endsWith(".md");
|
const isNote = tree[key].path.endsWith(".md");
|
||||||
tree[key].isNote = isNote;
|
tree[key].isNote = isNote;
|
||||||
if (isNote) {
|
if (isNote) {
|
||||||
tree[key].permalink = getPermalink(tree[key].path);
|
let { permalink, name } = getPermalinkAndName(tree[key].path);
|
||||||
tree[key].name = key.replace(".md", "");
|
tree[key].permalink = permalink
|
||||||
|
tree[key].name = name
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tree[key].isFolder = true;
|
tree[key].isFolder = true;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
---
|
---
|
||||||
title: "/{{ page.fileSlug }}/"
|
title: "/{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}/"
|
||||||
permalink: "notes/{{ page.fileSlug | slugify }}/"
|
permalink: "notes/{{ page.fileSlug | slugify }}/"
|
||||||
---
|
---
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>{{ page.fileSlug }}</title>
|
<title>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</title>
|
||||||
{%include "components/pageheader.njk"%}
|
{%include "components/pageheader.njk"%}
|
||||||
</head>
|
</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">
|
||||||
@ -23,7 +23,7 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
|
|||||||
|
|
||||||
<div class="content cm-s-obsidian">
|
<div class="content cm-s-obsidian">
|
||||||
{% if settings.dgShowInlineTitle === true %}
|
{% if settings.dgShowInlineTitle === true %}
|
||||||
<h1>{{ page.fileSlug }}</h1>
|
<h1>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</h1>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ content | link | highlight | safe}}
|
{{ content | link | highlight | safe}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -33,7 +33,7 @@ module.exports = {
|
|||||||
noteTitle: (data) => {
|
noteTitle: (data) => {
|
||||||
const currentnote = data.collections.gardenEntry && data.collections.gardenEntry[0];
|
const currentnote = data.collections.gardenEntry && data.collections.gardenEntry[0];
|
||||||
if (currentnote && currentnote.data) {
|
if (currentnote && currentnote.data) {
|
||||||
return currentnote.data.page.fileSlug;
|
return currentNote.data.title || currentnote.data.page.fileSlug;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
},
|
},
|
||||||
|
@ -5,7 +5,7 @@ eleventyExcludeFromCollections: true
|
|||||||
---
|
---
|
||||||
[{% for post in collections.note %}
|
[{% 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 }}",
|
"date":"{{ post.date }}",
|
||||||
"url":"{{ post.url }}",
|
"url":"{{ post.url }}",
|
||||||
"content": {{ post.templateContent | striptags(true) | link | jsonify | safe }}
|
"content": {{ post.templateContent | striptags(true) | link | jsonify | safe }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user