Skip to content

Add support for a non-root base path#34

Open
trwbox wants to merge 4 commits intoppeetteerrs:devfrom
trwbox:base-path-dev
Open

Add support for a non-root base path#34
trwbox wants to merge 4 commits intoppeetteerrs:devfrom
trwbox:base-path-dev

Conversation

@trwbox
Copy link
Contributor

@trwbox trwbox commented Jun 22, 2022

This adds an optional BASE_PATH in the configuration file that could be used for something like example.github.io/obsidian-notebook/.

The format has BASE_PATH with no slashes BASE_PATH = "obsidian-notebook", and requires that SITE_URL is changed accordingly, and including a trailing backslash to be like SITE_URL = https://example.github.io/obsidian-zola/

@ppeetteerrs
Copy link
Owner

@trwbox Thanks for the pull request! It looks good. Can I know if you have a working demo of a github.io hosted site? It would be helpful in additional to my offline testing.

@trwbox
Copy link
Contributor Author

trwbox commented Jun 27, 2022 via email

@trwbox
Copy link
Contributor Author

trwbox commented Jun 29, 2022

I got it created here is a link to the site:
https://www.trwbox.com/obsidian-path-vault/.

A good example page is Antenna on PCB to see the graph, and that in content links work.

And here is a link to the github repo:
https://github.com/trwbox/obsidian-path-vault

@ppeetteerrs
Copy link
Owner

The pull request seems reasonable. I would incorporate it in the next release. However, I might not include the BASE_PATH option in netlify.example.toml as it might be a little confusing to the majority. I will add a section in the README.md to explain how to host on alternative platforms.

@trwbox
Copy link
Contributor Author

trwbox commented Jul 7, 2022

That makes perfect sense. I added it for consistency sake, but have no issues if it is a part of the readme. I know this might be considered promoting my own project in asking, but if you add that section would you mind linking my Github Pages publishing tool?

https://github.com/trwbox/obsidian-zola-build-action

@master4x
Copy link

master4x commented Mar 9, 2023

When will this Pull Request be merged?
I also ran into this issue a few moth ago with GitHub Pages.

)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants