Skip to content

Commit

Permalink
Merge branch 'uroybd-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Eskild Steensen committed Jan 21, 2023
2 parents 255e1d5 + 0fe8b10 commit 9062a9c
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
dist
netlify/functions/search/data.json
netlify/functions/search/index.json
src/site/styles/theme.*.css
# Local Netlify folder
.netlify
.idea/
154 changes: 127 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "npm-run-all build:sass --parallel watch:*",
"start": "npm-run-all get-theme build:sass --parallel watch:*",
"watch:sass": "sass --watch src/site/styles:dist/styles",
"watch:eleventy": "cross-env ELEVENTY_ENV=dev eleventy --serve",
"build:eleventy": "cross-env ELEVENTY_ENV=prod NODE_OPTIONS=--max-old-space-size=4096 eleventy",
"build:sass": "sass src/site/styles:dist/styles",
"build": "npm-run-all build:*",
"get-theme": "node src/site/get-theme.js",
"build": "npm-run-all get-theme build:*",
"postbuild": "node src/site/lunr-index.js"
},
"keywords": [],
Expand All @@ -31,6 +32,7 @@
"eleventy-favicon": "^1.1.2",
"eleventy-plugin-toc": "^1.1.5",
"fs-file-tree": "^1.1.1",
"glob": "^8.1.0",
"gray-matter": "^4.0.3",
"lunr": "^2.3.9",
"markdown-it": "^13.0.1",
Expand Down
3 changes: 2 additions & 1 deletion plugin-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"src/helpers/constants.js",
"src/helpers/utils.js",
"src/helpers/linkUtils.js",
"netlify/functions/search/search.js"
"netlify/functions/search/search.js",
"src/site/get-theme.js"
]
}
55 changes: 21 additions & 34 deletions src/site/_data/meta.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
require("dotenv").config();
const axios = require("axios");
const fs = require("fs");
const crypto = require("crypto");
const glob = require("glob");

module.exports = async () => {
let baseUrl = process.env.SITE_BASE_URL || "";
if (baseUrl && !baseUrl.startsWith("http")) {
baseUrl = "https://" + baseUrl;
}
let themeStyle = glob.sync("src/site/styles/theme.*.css")[0] || "";
if (themeStyle) {
themeStyle = themeStyle.split("site")[1];
}
const meta = {
env: process.env.ELEVENTY_ENV,
theme: process.env.THEME,
themeStyle,
baseTheme: process.env.BASE_THEME || "dark",
siteName: process.env.SITE_NAME_HEADER || "Digital Garden",
siteBaseUrl: baseUrl,
};

module.exports = async() => {
let themeStyle = "";
let themeUrl = process.env.THEME;
if (themeUrl) {
//https://forum.obsidian.md/t/1-0-theme-migration-guide/42537
//Not all themes with no legacy mark have a theme.css file, so we need to check for it
try{
await axios.get(themeUrl);
}catch{
if(themeUrl.indexOf("theme.css") > -1){
themeUrl = themeUrl.replace("theme.css", "obsidian.css");
}
else if(themeUrl.indexOf("obsidian.css") > -1){
themeUrl = themeUrl.replace("obsidian.css", "theme.css");
}
}

const res = await axios.get(themeUrl);
themeStyle = `<style>${res.data}</style>`;
}
let baseUrl = process.env.SITE_BASE_URL || "";
if(baseUrl && !baseUrl.startsWith("http")){
baseUrl = "https://" + baseUrl;
}
const meta ={
env: process.env.ELEVENTY_ENV,
theme: process.env.THEME,
themeStyle: themeStyle,
baseTheme: process.env.BASE_THEME || "dark",
siteName: process.env.SITE_NAME_HEADER || "Digital Garden",
siteBaseUrl: baseUrl,
};

return meta;
return meta;
};
2 changes: 1 addition & 1 deletion src/site/_includes/components/pageheader.njk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<link href="/styles/digital-garden-base.css" rel="stylesheet">
{%-if meta.themeStyle%}
<link href="/styles/obsidian-base.css" rel="stylesheet">
{{meta.themeStyle | safe}}
<link href="{{meta.themeStyle}}" rel="stylesheet">
{% else %}
<link href="/styles/style.css" rel="stylesheet">
{%endif%}
Expand Down
Loading

0 comments on commit 9062a9c

Please sign in to comment.