Skip to content

Commit

Permalink
Fix page context url path.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeanwallace committed Mar 25, 2024
1 parent b595cab commit f5d1c8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions jinjabread/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ def _get_sibling_context_list(self):

def get_context(self):
file_path = self.output_path.relative_to(self.site.config.output_dir)
url_path = file_path.with_suffix("")
if url_path.name == "index":
url_path = url_path.parent
if file_path.stem == "index":
url_path = "/" + file_path.parent.as_posix() + "/"
else:
url_path = "/" + file_path.with_suffix("").as_posix()
context = self.site.config.context | {
"file_path": file_path,
"url_path": f"/{url_path.as_posix()}",
"file_path": file_path.as_posix(),
"url_path": url_path,
}
if self.content_path.stem == "index":
context["pages"] = self._get_sibling_context_list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

{% for page in pages|sort(attribute="url_path") %}
## {{ page.title }}

{{ page.content }}

Read more [here]({{ page.url_path }}).

---
{% endfor %}
4 changes: 4 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class TestHtmlMixin:

def assertHtmlEqual(self, first, second):
self.maxDiff = None
return self.assertEqual(
jinjabread.prettify_html(first), jinjabread.prettify_html(second)
)
Expand Down Expand Up @@ -375,12 +376,15 @@ def test_directory_index_markdown_content_with_directory_siblings(self):
<h1>Look on my Works, ye Mighty, and despair!</h1>
<h2>Post 1</h2>
<p>I am post 1.</p>
<p>Read more <a href="/post1/">here</a>.</p>
<hr/>
<h2>Post 2</h2>
<p>I am post 2.</p>
<p>Read more <a href="/post2/">here</a>.</p>
<hr/>
<h2>Post 3</h2>
<p>I am post 3.</p>
<p>Read more <a href="/post3/">here</a>.</p>
<hr/>
</main>
<footer>This is a footer.</footer>
Expand Down

0 comments on commit f5d1c8b

Please sign in to comment.