diff --git a/.gitignore b/.gitignore index 900c5714..62e9c48f 100644 --- a/.gitignore +++ b/.gitignore @@ -160,8 +160,7 @@ cython_debug/ .vs .vscode -.data_path -.data_paths +.vault_path backup data diff --git a/README.md b/README.md index 88d7c386..a681ba4e 100644 --- a/README.md +++ b/README.md @@ -18,16 +18,18 @@ Special Thanks: Wikilink parsing is powered by [obsidian-export](https://github. # Announcements -**v1.2.2 Collapsible Sidebar! 📄** +**v1.3.0 Collapsible Sidebar! 📄** Bug Fixes: -- Breadcrumb List Schema had error (from Adidoks), now its fixed -- Added instructions on automatic sitemap update to Google for search indexing +- Fixed some more bugs related to unconventional filenames (e.g. containing "." and other special characters) + Improvements: -- Sidebar collapse + option to set default collapse state (implemented for those few crazy people with over a thousand notes...) +- Better local test setup (see `Local Testing` below) +- Configurable root section name +- Configurable footer content # Setup @@ -78,22 +80,19 @@ providers = [ ] ``` - # Example Site > Do not copy `netlify.toml` from example site, it is unstable. Please reference from `netlify.example.toml`. The [example site](https://peteryuen.netlify.app/) shows the capabilities of `obsidian-zola`. Note that the example site uses the `dev` branch of `obsidian-zola`. If you see features that are available in the example site but are not available in the main branch yet, consider trying out the `dev` (unstable) branch. Exact method can be referenced from the [example repo's](https://github.com/ppeetteerrs/obsidian-pkm) `netlify.toml`. -# Local Building - -These steps were tested on an fresh install of Ubuntu Server 20.04 install as of 12 May 2022 +# Local Testing (Ubuntu) [thanks @trwbox] -- Install zola from the instuctions on the site ```https://www.getzola.org/documentation/getting-started/installation/``` -- Run the following commands to install other needed dependencies ```sudo apt install python-is-python3 python3-pip``` and ```pip3 install python-slugify``` -- Use ```git clone https://github.com/ppeetteerrs/obsidian-zola``` to clone the repo to somewhere other than inside the Obsidian vault folder -- Set the path to the Obsisian vault in the ```local-run.sh``` script -- use ```./local-run.sh``` to run the site +- Install zola from the instuctions on the site `https://www.getzola.org/documentation/getting-started/installation/` +- Run the following commands to install other needed dependencies `sudo apt install python-is-python3 python3-pip` and `pip3 install python-slugify rtoml` (or use `conda` / `mamba`) +- Use `git clone https://github.com/ppeetteerrs/obsidian-zola` to clone the repo to somewhere other than inside the Obsidian vault folder +- Set the path to the Obsisian vault using a `.vault_path` file or the `$VAULT` environment variable +- use `./local-run.sh` to run the site # Features diff --git a/convert.py b/convert.py index 5254ecda..b41ac171 100644 --- a/convert.py +++ b/convert.py @@ -17,6 +17,8 @@ Settings.parse_env() Settings.sub_file(site_dir / "config.toml") Settings.sub_file(site_dir / "content/_index.md") + Settings.sub_file(site_dir / "templates/macros/footer.html") + Settings.sub_file(site_dir / "static/js/graph.js") nodes: Dict[str, str] = {} edges: List[Tuple[str, str]] = [] diff --git a/env.py b/env.py new file mode 100644 index 00000000..54f3f0dc --- /dev/null +++ b/env.py @@ -0,0 +1,15 @@ +from os import environ +from pathlib import Path + +import rtoml + +if __name__ == "__main__": + env_vars = rtoml.load(Path(environ["VAULT"]) / "netlify.toml")["build"][ + "environment" + ] + for k, v in env_vars.items(): + val = v.replace("'", "'\\''") + print( + f"export {k}='{val}'", + file=open("env.sh", "a"), + ) diff --git a/local-run.sh b/local-run.sh index 9e204cb3..d91822e9 100755 --- a/local-run.sh +++ b/local-run.sh @@ -1,43 +1,49 @@ #!/bin/bash # Check for python-is-python3 installed -if ! command -v python &> /dev/null -then - echo "It appears you do not have python-is-python3 installed" - exit 1 +if ! command -v python &>/dev/null; then + echo "It appears you do not have python-is-python3 installed" + exit 1 fi # Check for zola being installed -if ! command -v zola &> /dev/null -then - echo "zola could not be found please install it from https://www.getzola.org/documentation/getting-started/installation" - exit 1 +if ! command -v zola &>/dev/null; then + echo "zola could not be found please install it from https://www.getzola.org/documentation/getting-started/installation" + exit 1 fi # Check for correct slugify package PYTHON_ERROR=$(eval "python -c 'from slugify import slugify; print(slugify(\"Test String One\"))'" 2>&1) -if [[ $PYTHON_ERROR != "test-string-one" ]] -then - if [[ $PYTHON_ERROR =~ "NameError" ]] - then - echo "It appears you have the wrong version of slugify installed, the required pip package is python-slugify" - else - echo "It appears you do not have slugify installed. Install it with 'pip install python-slugify'" - fi - exit 1 +if [[ $PYTHON_ERROR != "test-string-one" ]]; then + if [[ $PYTHON_ERROR =~ "NameError" ]]; then + echo "It appears you have the wrong version of slugify installed, the required pip package is python-slugify" + else + echo "It appears you do not have slugify installed. Install it with 'pip install python-slugify'" + fi + exit 1 +fi + +# Check for rtoml package +PYTHON_ERROR=$(eval "python -c 'import rtoml'" 2>&1) + +if [[ $PYTHON_ERROR =~ "ModuleNotFoundError" ]]; then + echo "It appears you do not have rtoml installed. Install it with 'pip install rtoml'" + exit 1 fi -# Path to the vault -export VAULT="" # Check that the vault got set if [[ -z "${VAULT}" ]]; then - echo "Path to the obsisian vault is not set, please set the path in local-run.sh" - exit 1 + if [[ -f ".vault_path" ]]; then + export VAULT=$(cat .vault_path) + else + echo "Path to the obsidian vault is not set, please set the path using in the $(.vault_path) file or $VAULT env variable" + exit 1 + fi fi -# Pull environment variables from the netlify.toml when building -eval $(awk '/\[build.environment\]/{flag=1;next}/^\s*$/{flag=0} {if (flag && $1 != "#" && $1 != "") {printf("export %s=", $1)} if (flag && $1 != "#" && $1 != "") for(i=3; i<=NF; i++) if(i==NF) {printf("%s\n", $i)} else printf("%s ", $i)}' netlify.toml | sed 's/\r$//') +# Pull environment variables from the vault's netlify.toml when building (by generating env.sh to be sourced) +python env.py # Set the site and repo url as local since locally built export SITE_URL=local @@ -57,7 +63,7 @@ else fi # Run conversion script -python convert.py +source env.sh && python convert.py && rm env.sh # Serve Zola site zola --root=build serve diff --git a/netlify.example.toml b/netlify.example.toml index 8dc22520..6d6f40a8 100644 --- a/netlify.example.toml +++ b/netlify.example.toml @@ -35,3 +35,42 @@ HOME_GRAPH = "y" PAGE_GRAPH = "y" # (Optional, default false) Whether sidebar sections should be collapsed by default. SIDEBAR_COLLAPSED = "" +# (Optional, default blank) Additional footer content. +FOOTER = "" +# (Optional, default main) Root section name. +ROOT_SECTION_NAME = "main" +# (Optional) visjs graph options. Can remove if desired. +GRAPH_OPTIONS = """ + { + nodes: { + shape: "star", + color: isDark() ? "#8c8e91" : "#dee2e6", + font: { + face: "Inter", + color: isDark() ? "#c9cdd1" : "#616469", + strokeColor: isDark() ? "#c9cdd1" : "#616469", + }, + scaling: { + label: { + enabled: true, + }, + }, + }, + edges: { + color: { inherit: "both" }, + width: 0.8, + smooth: { + type: "continuous", + }, + hoverWidth: 4, + }, + interaction: { + hover: true, + }, + height: "100%", + width: "100%", + physics: { + solver: "repulsion", + }, + } + """ diff --git a/utils.py b/utils.py index bab3db8d..6f0d00eb 100644 --- a/utils.py +++ b/utils.py @@ -168,7 +168,11 @@ def __init__(self, path: Path): def section_title(self) -> str: """Gets the title of the section.""" title = str(self.old_rel_path).replace('"', r"\"") - return title if (title != "" and title != ".") else "main" + return ( + title + if (title != "" and title != ".") + else Settings.options["ROOT_SECTION_NAME"] or "main" + ) @property def section_sidebar(self) -> str: @@ -178,7 +182,11 @@ def section_sidebar(self) -> str: sidebar = ( sidebar.count("/") * Settings.options["SUBSECTION_SYMBOL"] ) + sidebar.split("/")[-1] - return sidebar if (sidebar != "" and sidebar != ".") else "main" + return ( + sidebar + if (sidebar != "" and sidebar != ".") + else Settings.options["ROOT_SECTION_NAME"] or "main" + ) def write_to(self, child: str, content: Union[str, List[str]]): """Writes content to a child path under new path.""" @@ -289,6 +297,42 @@ class Settings: "GRAPH_LINK_REPLACE": "", "STRICT_LINE_BREAKS": "y", "SIDEBAR_COLLAPSED": "", + "FOOTER": "", + "ROOT_SECTION_NAME": "main", + "GRAPH_OPTIONS": """ + { + nodes: { + shape: "dot", + color: isDark() ? "#8c8e91" : "#dee2e6", + font: { + face: "Inter", + color: isDark() ? "#c9cdd1" : "#616469", + strokeColor: isDark() ? "#c9cdd1" : "#616469", + }, + scaling: { + label: { + enabled: true, + }, + }, + }, + edges: { + color: { inherit: "both" }, + width: 0.8, + smooth: { + type: "continuous", + }, + hoverWidth: 4, + }, + interaction: { + hover: true, + }, + height: "100%", + width: "100%", + physics: { + solver: "repulsion", + }, + } + """, } @classmethod diff --git a/zola/static/js/graph.js b/zola/static/js/graph.js index 1db3ca63..743ebb86 100644 --- a/zola/static/js/graph.js +++ b/zola/static/js/graph.js @@ -63,38 +63,7 @@ if (curr_node) { } // Construct graph -var options = { - nodes: { - shape: "dot", - color: isDark() ? "#8c8e91" : "#dee2e6", - font: { - face: "Inter", - color: isDark() ? "#c9cdd1" : "#616469", - strokeColor: isDark() ? "#c9cdd1" : "#616469", - }, - scaling: { - label: { - enabled: true, - }, - }, - }, - edges: { - color: { inherit: "both" }, - width: 0.8, - smooth: { - type: "continuous", - }, - hoverWidth: 4, - }, - interaction: { - hover: true, - }, - height: "100%", - width: "100%", - physics: { - solver: "repulsion", - }, -}; +var options = ___GRAPH_OPTIONS___; var graph = new vis.Network( container, diff --git a/zola/templates/macros/footer.html b/zola/templates/macros/footer.html index 495e3a49..a63fef44 100644 --- a/zola/templates/macros/footer.html +++ b/zola/templates/macros/footer.html @@ -3,7 +3,7 @@
- Powered by obsidian-zola + ___FOOTER___Powered by obsidian-zola