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);
|
||||
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 {
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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 "";
|
||||
},
|
||||
|
@ -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 }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user