Skip to content

Commit

Permalink
Bug Fixes and Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Yuen authored and Peter Yuen committed Jun 9, 2022
1 parent 5d1ef4d commit 79214eb
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 74 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ cython_debug/

.vs
.vscode
.data_path
.data_paths
.vault_path

backup
data
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = []
Expand Down
15 changes: 15 additions & 0 deletions env.py
Original file line number Diff line number Diff line change
@@ -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"),
)
54 changes: 30 additions & 24 deletions local-run.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
39 changes: 39 additions & 0 deletions netlify.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
"""
48 changes: 46 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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."""
Expand Down Expand Up @@ -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
Expand Down
33 changes: 1 addition & 32 deletions zola/static/js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion zola/templates/macros/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="container">
<div class="row">
<div class="col-lg-16 order-last order-lg-first" style="text-align: center;">
Powered by <a href="https://github.com/ppeetteerrs/obsidian-zola">obsidian-zola</a>
___FOOTER___Powered by <a href="https://github.com/ppeetteerrs/obsidian-zola">obsidian-zola</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 79214eb

Please sign in to comment.