Skip to content

Commit 8698b29

Browse files
committed
Include archived files in archived index
1 parent 26a06a3 commit 8698b29

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

hastie/content.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def determine_category_from_path(file_parent: Path, content_dir: Path) -> str:
111111
return category_path.parent.relative_to(content_dir).as_posix()
112112

113113

114-
def gather_categories(content_dir: Path, config: dict[str, Any]) -> list[dict[str, Any]]:
114+
def gather_categories(
115+
content_dir: Path, config: dict[str, Any]
116+
) -> list[dict[str, Any]]:
115117
"""Build list of categories from the filesystem."""
116118
categories = []
117119
baseurl = config["site"]["baseurl"]
@@ -173,7 +175,9 @@ def gather_subpages(filepath: Path, config: dict[str, Any]) -> list[dict[str, An
173175
return subpages
174176

175177

176-
def filter_category_pages(category: str, pages: list[dict[str, Any]]) -> list[dict[str, Any]]:
178+
def filter_category_pages(
179+
category: str, pages: list[dict[str, Any]], include_archived: bool = False
180+
) -> list[dict[str, Any]]:
177181
category_pages = []
178182

179183
for page in pages:
@@ -183,7 +187,7 @@ def filter_category_pages(category: str, pages: list[dict[str, Any]]) -> list[di
183187
if "draft" in page:
184188
continue
185189

186-
if "archive" in page:
190+
if "archive" in page and not include_archived:
187191
continue
188192

189193
category_pages.append(page)

hastie/main.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def main():
7272
sys.exit()
7373

7474
## filter pages to those within category
75-
category_pages = content.filter_category_pages(page["category"], pages)
75+
# If this page is archived or has include_archived: true, include archived pages in the listing
76+
include_archived = "archive" in page or page.get("include_archived", False)
77+
category_pages = content.filter_category_pages(
78+
page["category"], pages, include_archived
79+
)
7680

7781
# sort pages
7882
# human_sort(category_pages, "title")
@@ -115,8 +119,11 @@ def main():
115119
# remove drafts from category pages
116120
category_pages = list(filter(lambda p: "draft" not in p, category_pages))
117121

118-
# remove archived from category pages
119-
category_pages = list(filter(lambda p: "archive" not in p, category_pages))
122+
# remove archived from category pages (unless this category page itself is archived or has include_archived: true)
123+
if "archive" not in cat["page"] and not cat["page"].get(
124+
"include_archived", False
125+
):
126+
category_pages = list(filter(lambda p: "archive" not in p, category_pages))
120127

121128
# sort by title
122129
human_sort(category_pages, "name")

hastie/rss.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""RSS Module"""
2+
23
import operator
34
from datetime import datetime
45
from email.utils import formatdate

hastie/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ def timer(st: float = 0, s=""):
5454
if st == 0:
5555
return time.time()
5656

57-
print(f"Elapsed for {s}: {time.time()-st:.1f}")
57+
print(f"Elapsed for {s}: {time.time() - st:.1f}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[project]
33
name = "hastie"
4-
version = "1.1.0-1"
4+
version = "1.1.0-b2"
55
description = "A static site generator"
66
authors = [{name = "Marcus Kazmierczak", email = "marcus@mkaz.com"}]
77
license = {text = "MIT"}

tests/test_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Test module for Hastie resources."""
1+
"""Test module for Hastie resources."""
22

33
from pathlib import Path
44
from typing import Dict

0 commit comments

Comments
 (0)