Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions local-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ fi

# Pull environment variables from the vault's netlify.toml when building (by generating env.sh to be sourced)
python env.py
source env.sh && rm env.sh

# Set the site and repo url as local since locally built
# Set the site and repo url as local since locally built, alongside resetting the base path to none
export SITE_URL=local
export REPO_URL=local
export BASE_PATH=""

# Remove previous build and sync Zola template contents
rm -rf build
Expand All @@ -63,7 +65,7 @@ else
fi

# Run conversion script
source env.sh && python convert.py && rm env.sh
python convert.py

# Serve Zola site
zola --root=build serve
2 changes: 2 additions & 0 deletions netlify.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ SITE_TITLE = "Someone's Second 🧠"
SITE_TITLE_TAB = ""
# (REQUIRED) Netlify site URL
SITE_URL = ""
# (Optional) The base path of the website if not the root (e.g. https://example.site.com/obsidian-zola/) this need to have no leading or trailing backslahes, alongside changing the SITE_URL to reflect the new location
BASE_PATH = ""
# (Optional) Site Timezone
TIMEZONE = "Asia/Hong_Kong"
ZOLA_VERSION = "0.15.2"
Expand Down
15 changes: 11 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ def abs_url(self, doc_path: "DocPath") -> str:
.resolve()
.relative_to(docs_dir)
)
new_rel_path = quote(str(slugify_path(new_rel_path, False)))
new_rel_path = quote(str(slugify_path(new_rel_path, True)))
if(Settings.options["BASE_PATH"] != ""):
Copy link

@SherAndrei SherAndrei Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change in the abs_url method breaks all the links in the main graph page, since when building a graph no one takes a hint that we should either strip the BASE_URL or count it in. I've found a better solution. Here is the diff

diff --git a/utils.py b/utils.py
index 4f644c3..9aa596d 100644
--- a/utils.py
+++ b/utils.py
@@ -132,8 +132,9 @@ class DocLink:
 
         for link in cls.get_links(line):
             abs_url = link.abs_url(doc_path)
+            replace_with = f"[{link.title}]({Settings.options['SITE_URL']}{abs_url}{link.header})"
             parsed = parsed.replace(
-                link.combined, f"[{link.title}]({abs_url}{link.header})"
+                link.combined, replace_with
             )
             linked.append(abs_url)
 
@@ -445,7 +446,7 @@ def parse_graph(nodes: Dict[str, str], edges: List[Tuple[str, str]]):
             {
                 "id": node_ids[url],
                 "label": title,
-                "url": url,
+                "url": f"{Settings.options['SITE_URL']}{url}",
                 "color": PASTEL_COLORS[top_nodes[url]] if url in top_nodes else None,
                 "value": math.log10(edge_counts[url] + 1) + 1,
                 "opacity": 0.1,

It preserves all the links in the project and allows to use non-root base path

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found better solution using zola's features: SherAndrei@9ef636b

return f"/{Settings.options['BASE_PATH']}/docs/{new_rel_path}"
else:
return f"/docs/{new_rel_path}"

return f"/docs/{new_rel_path}"
except Exception:
print(f"Invalid link found: {doc_path.old_rel_path}")
return "/404"
Expand Down Expand Up @@ -254,7 +257,10 @@ def copy(self):
def abs_url(self) -> str:
"""Returns an absolute URL to the page."""
assert self.is_md
return quote(f"/docs/{str(self.new_rel_path)[:-3]}")
if(Settings.options['BASE_PATH'] != ""):
return quote(f"/{Settings.options['BASE_PATH']}/docs/{str(self.new_rel_path)[:-3]}")
else:
return quote(f"/docs/{str(self.new_rel_path)[:-3]}")

def edge(self, other: str) -> Tuple[str, str]:
"""Gets an edge from page's URL to another URL."""
Expand All @@ -279,6 +285,7 @@ class Settings:
# Default options
options: Dict[str, Optional[str]] = {
"SITE_URL": None,
"BASE_PATH": "",
"SITE_TITLE": "Someone's Second 🧠",
"TIMEZONE": "Asia/Hong_Kong",
"REPO_URL": None,
Expand Down Expand Up @@ -438,7 +445,7 @@ def parse_graph(nodes: Dict[str, str], edges: List[Tuple[str, str]]):
list(sorted(edge_counts.items(), key=lambda k: -k[1]))[: len(PASTEL_COLORS)]
)
}

# Generate graph data
graph_info = {
"nodes": [
Expand Down