Skip to content

Commit

Permalink
Always use posix paths on generated relative paths in html (#206)
Browse files Browse the repository at this point in the history
* aways use poxix paths on generated relative paths in html

* add posix compliant relative paths with get_url_relpath and OS dependent with get_relpath

* format long line
  • Loading branch information
aivuk committed May 2, 2022
1 parent 4a71dc9 commit e230e31
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions livemark/helpers.py
@@ -1,5 +1,6 @@
import io
import os
import posixpath
import sys
import shutil
import tempfile
Expand All @@ -22,6 +23,10 @@ def read_asset(*paths):
return file.read().strip()


def get_url_relpath(path, current):
return posixpath.relpath(path, os.path.dirname(current))


def get_relpath(path, current):
return os.path.relpath(path, os.path.dirname(current))

Expand Down
4 changes: 2 additions & 2 deletions livemark/plugins/blog/plugin.py
Expand Up @@ -25,7 +25,7 @@ def path(self):
@property
def relpath(self):
path = f"{self.path}/index.html"
return helpers.get_relpath(path, self.document.path)
return helpers.get_url_relpath(path, self.document.path)

@property
def items(self):
Expand All @@ -35,7 +35,7 @@ def items(self):
index_path = "/".join([self.path, "index"])
for document in self.document.project.documents:
if document.path.startswith(self.path) and document.path != index_path:
relpath = helpers.get_relpath(document.path, self.document.path)
relpath = helpers.get_url_relpath(document.path, self.document.path)
items.append({"document": document, "relpath": relpath})
return items

Expand Down
2 changes: 1 addition & 1 deletion livemark/plugins/brand/plugin.py
Expand Up @@ -16,7 +16,7 @@ class BrandPlugin(Plugin):

@property
def path(self):
return helpers.get_relpath(".", self.document.path)
return helpers.get_url_relpath(".", self.document.path)

@property
def text(self):
Expand Down
6 changes: 4 additions & 2 deletions livemark/plugins/pages/plugin.py
Expand Up @@ -42,7 +42,9 @@ def items(self):
document = self.document.project.get_document(subitem["path"])
subitem.setdefault("name", document.get_plugin("site").name)
subitem["active"] = False
subitem["relpath"] = helpers.get_relpath(subitem["path"], self.current)
subitem["relpath"] = helpers.get_url_relpath(
subitem["path"], self.current
)
if subitem["path"] == self.current:
item["active"] = True
subitem["active"] = True
Expand All @@ -51,7 +53,7 @@ def items(self):
if not subitems:
document = self.document.project.get_document(item["path"])
item.setdefault("name", document.get_plugin("site").name)
item["relpath"] = helpers.get_relpath(item["path"], self.current)
item["relpath"] = helpers.get_url_relpath(item["path"], self.current)
if item["path"] == self.current:
item["active"] = True

Expand Down
2 changes: 1 addition & 1 deletion livemark/plugins/search/plugin.py
Expand Up @@ -17,7 +17,7 @@ def items(self):
item = {}
item["name"] = document.get_plugin("site").name
item["path"] = document.path
item["relpath"] = helpers.get_relpath(document.path, self.document.path)
item["relpath"] = helpers.get_url_relpath(document.path, self.document.path)
item["text"] = document.content
items.append(item)
return items
Expand Down
4 changes: 2 additions & 2 deletions livemark/plugins/signs/plugin.py
Expand Up @@ -30,11 +30,11 @@ def items(self):
if current_number:
if current_number > 1:
document = documents[current_number - 2]
path = helpers.get_relpath(document.path, self.current)
path = helpers.get_url_relpath(document.path, self.current)
prev = {"name": document.name, "path": path}
if current_number < len(documents):
document = documents[current_number]
path = helpers.get_relpath(document.path, self.current)
path = helpers.get_url_relpath(document.path, self.current)
next = {"name": document.name, "path": path}
return {"prev": prev, "next": next}

Expand Down
2 changes: 1 addition & 1 deletion livemark/plugins/site/plugin.py
Expand Up @@ -45,7 +45,7 @@ def keywords(self):
@property
def favicon(self):
if self.config.get("favicon"):
return helpers.get_relpath(self.config.get("favicon"), self.document.path)
return helpers.get_url_relpath(self.config.get("favicon"), self.document.path)

@property
def layout(self):
Expand Down

0 comments on commit e230e31

Please sign in to comment.