diff --git a/CONFIG.md b/CONFIG.md index adadb888..ceda4e6d 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -40,7 +40,7 @@ How to sort your pages inside a folder ("title" or "date"). Default: "title". F Google Analytics Measurement ID. Default: "". ### `SLUGIFY` -Whether to slugify URLs. Set to "" to disable. Default: "y". +Whether to slugify URLs. Set to "" to disable (use at your own risk, filenames with special symbols might not show up correctly in the graph view). Default: "y". ### `HOME_GRAPH` Shows knowledge graph on home page. Put "" to disable. Default: "y". diff --git a/utils.py b/utils.py index e4818f7d..abf2e81e 100644 --- a/utils.py +++ b/utils.py @@ -10,7 +10,7 @@ from pathlib import Path from pprint import PrettyPrinter from typing import Dict, List, Optional, Tuple, Union -from urllib.parse import unquote +from urllib.parse import quote, unquote from slugify import slugify @@ -111,7 +111,8 @@ def abs_url(self, doc_path: "DocPath") -> str: .resolve() .relative_to(docs_dir) ) - new_rel_path = slugify_path(new_rel_path) + new_rel_path = quote(str(slugify_path(new_rel_path))) + return f"/docs/{new_rel_path}" except Exception: print(f"Invalid link found: {doc_path.old_rel_path}") @@ -240,7 +241,7 @@ def copy(self): def abs_url(self) -> str: """Returns an absolute URL to the page.""" assert self.is_md - return f"/docs/{str(self.new_rel_path)[:-3]}" + 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.""" diff --git a/zola/static/js/graph.js b/zola/static/js/graph.js index 0c62778f..1db3ca63 100644 --- a/zola/static/js/graph.js +++ b/zola/static/js/graph.js @@ -13,7 +13,11 @@ if (curr_url.endsWith("/")) { var container = document.getElementById("graph"); // Parse nodes and edges -var curr_node = graph_data.nodes.filter((node) => node.url == curr_url); +try { + var curr_node = graph_data.nodes.filter((node) => decodeURI(node.url) == curr_url); +} catch (error) { + var curr_node = null; +} var nodes = null; var edges = new vis.DataSet(graph_data.edges);