Use default note setting from .env

This commit is contained in:
Ole Eskild Steensen 2022-10-24 22:26:50 +02:00
parent 43d0d01b61
commit b2b5253f30
7 changed files with 82 additions and 39 deletions

1
.env
View File

@ -1,3 +1,4 @@
#THEME=https://raw.githubusercontent.com/colineckert/obsidian-things/main/obsidian.css
#THEME=https://github.com/kepano/obsidian-minimal/blob/master/obsidian.css
#BASE_THEME=light
dgHomeLink=true

View File

@ -8,11 +8,12 @@ module.exports = async() => {
const res = await axios.get(process.env.THEME)
themeStyle = `<style>${res.data}</style>`;
}
return {
const meta ={
env: process.env.ELEVENTY_ENV,
theme: process.env.THEME,
themeStyle: themeStyle,
baseTheme: process.env.BASE_THEME || "dark"
}
baseTheme: process.env.BASE_THEME || "dark",
};
return meta;
};

View File

@ -14,14 +14,14 @@
<div x-show="open || !isDesktop" class="sidebar-container" style="display: none;">
{%if dgShowLocalGraph === true%}
{%if settings.dgShowLocalGraph === true%}
<div x-show="isDesktop">
<h3>Graph</h3>
<div id="link-graph" style="margin-bottom:20px; background-color: var(--background-primary); border-radius: 10px; width: fit-content;"></div>
</div>
{%endif%}
{%if dgShowBacklinks === true %}
{%if settings.dgShowBacklinks === true %}
<h3>Links to this page</h3>
{%- if backlinks.length === 0 -%}
<div class="backlink-card">
@ -39,7 +39,7 @@
</div>
</div>
{%if dgShowLocalGraph === true %}
{%if settings.dgShowLocalGraph === true %}
{%include "components/graphScript.njk"%}
{% endif %}
@ -47,7 +47,7 @@
document.addEventListener('alpine:init', () => {
const isDesktop = window.innerWidth >= 1100;
{% if dgShowLocalGraph === true %}
{% if settings.dgShowLocalGraph === true %}
renderGraph(600, 400);
{% endif %}

View File

@ -12,15 +12,16 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
{%include "components/notegrowthhistory.njk"%}
<div class="content">
{% if dgHomeLink !== false%}
{% if settings.dgHomeLink !== false%}
<a href="/">🏡 Back Home</a>
{% endif %}
{% if dgShowInlineTitle === true %}
{# Dra dette opp i en egen greie for hver setting. Definer disse settingene i en klasse og lag en settings.js lik meta.js. Gå gjennom hver key og kjør denne logikken for å sette den. #}
{% if settings.dgShowInlineTitle === true %}
<h1>{{ page.fileSlug }}</h1>
{% endif %}
{{ content | link | highlight | safe}}
{% if dgShowBacklinks === true or dgShowLocalGraph === true%}
{% if settings.dgShowBacklinks === true or settings.dgShowLocalGraph === true%}
{%include "components/sidebar.njk"%}
{% endif %}
</div>

View File

@ -1,10 +1,20 @@
require("dotenv").config();
const wikilink = /\[\[(.*?\|.*?)\]\]/g
function caselessCompare(a, b) {
return a.toLowerCase() === b.toLowerCase();
}
//Duplicated in notes.11tydata.js because new files means I need to update the plugin
const allSettings = [
"dgHomeLink",
"dgPassFrontmatter",
"dgShowBacklinks",
"dgShowLocalGraph",
"dgShowInlineTitle"
];
module.exports = {
eleventyComputed: {
backlinks: (data) => {
@ -82,20 +92,28 @@ module.exports = {
return outbound;
},
dgShowLocalGraph: (data) => {
const currentNote = data.collections.gardenEntry && data.collections.gardenEntry[0];
if(currentNote && currentNote.data && currentNote.data.dgShowLocalGraph){
return true;
}
return false;
},
dgShowBacklinks: (data) =>{
settings: (data) => {
const currentnote = data.collections.gardenEntry && data.collections.gardenEntry[0];
if(currentnote && currentnote.data && currentnote.data.dgShowLocalGraph){
return true;
if (currentnote && currentnote.data) {
const noteSettings = {};
allSettings.forEach(setting => {
let noteSetting = currentnote.data[setting];
let globalSetting = process.env[setting];
let settingValue = (noteSetting || (globalSetting === 'true' && noteSetting !== false));
noteSettings[setting] = settingValue;
});
return noteSettings;
}
return false;
return {};
},
noteTitle: (data) => {
const currentnote = data.collections.gardenEntry && data.collections.gardenEntry[0];
if (currentnote && currentnote.data) {
return currentnote.data.page.fileSlug;
}
return "";
}
}
}

View File

@ -1,22 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{ collections.gardenEntry[0].fileSlug }}</title>
<title>{{ noteTitle }}</title>
{%include "components/pageheader.njk"%}
</head>
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered">
{%include "components/notegrowthhistory.njk"%}
<div class="content">
{% if collections.gardenEntry[0].data.dgShowInlineTitle === true %}
<h1>{{ collections.gardenEntry[0].fileSlug }}</h1>
{% if settings.dgShowInlineTitle === true %}
<h1>{{ noteTitle }}</h1>
{% endif %}
{%- for garden in collections.gardenEntry -%}
{{garden.templateContent | link | highlight | safe }}
{%- endfor -%}
{%if collections.gardenEntry[0].data.dgShowBacklinks === true or collections.gardenEntry[0].data.dgShowLocalGraph === true%}
{%if settings.dgShowBacklinks === true or settings.dgShowLocalGraph === true%}
{%include "components/sidebar.njk" %}
{%endif%}
</div>

View File

@ -1,10 +1,21 @@
require("dotenv").config();
const wikilink = /\[\[(.*?\|.*?)\]\]/g
function caselessCompare(a, b) {
return a.toLowerCase() === b.toLowerCase();
}
//Duplicated in index.11tydata.js because new files means I need to update the plugin
const allSettings = [
"dgHomeLink",
"dgPassFrontmatter",
"dgShowBacklinks",
"dgShowLocalGraph",
"dgShowInlineTitle"
];
module.exports = {
eleventyComputed: {
backlinks: (data) => {
@ -81,6 +92,17 @@ module.exports = {
return outbound;
},
settings: (data) => {
const noteSettings = {};
allSettings.forEach(setting => {
let noteSetting = data[setting];
let globalSetting = process.env[setting];
let settingValue = (noteSetting || (globalSetting === 'true' && noteSetting !== false));
noteSettings[setting] = settingValue;
});
return noteSettings;
}
}
}