Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ jobs:
URL: ${{ steps.deploy.outputs.deployment-url }}
PR_NUMBER: ${{ github.event.number }}
run: |
gh pr comment "$PR_NUMBER" --edit-last --body "**Docs Site** preview: $URL"
gh pr comment "$PR_NUMBER" --edit-last --body "**Docs Site** preview: $URL" \
|| gh pr comment "$PR_NUMBER" --body "**Docs Site** preview: $URL"
1 change: 1 addition & 0 deletions docs/rockgarden.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title = "Rockgarden"
clean_urls = true
output = "../_site"
ignore_patterns = []
timezone = "US/Eastern"

[nav]
sort = "files-first"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"markdown-it-py>=3.0.0",
"python-frontmatter>=1.0.0",
"linkify-it-py>=2.0.3",
"tzdata>=2024.1",
]

[project.scripts]
Expand Down
2 changes: 2 additions & 0 deletions src/rockgarden/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SiteConfig:
output: Path = field(default_factory=lambda: Path("_site"))
clean_urls: bool = True
base_url: str = ""
timezone: str = "UTC"


@dataclass
Expand Down Expand Up @@ -140,6 +141,7 @@ def from_dict(cls, data: dict) -> "Config":
output=Path(site_data.get("output", "_site")),
clean_urls=site_data.get("clean_urls", True),
base_url=site_data.get("base_url", "").rstrip("/"),
timezone=site_data.get("timezone", "UTC"),
)

icons_dir_raw = build_data.get("icons_dir")
Expand Down
20 changes: 19 additions & 1 deletion src/rockgarden/render/engine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Jinja2 template engine setup."""

from datetime import datetime
from datetime import timezone as dt_timezone
from pathlib import Path
from zoneinfo import ZoneInfo

from jinja2 import ChoiceLoader, Environment, FileSystemLoader, PackageLoader

Expand All @@ -9,6 +12,19 @@
from rockgarden.nav.tree import NavNode


def _make_format_datetime(tz_name: str):
tz = ZoneInfo(tz_name)

This comment was marked as outdated.

This comment was marked as outdated.


def format_datetime(dt: datetime | None, fmt: str = "%Y-%m-%d") -> str:
if dt is None:
return ""
if dt.tzinfo is None:
dt = dt.replace(tzinfo=dt_timezone.utc)
return dt.astimezone(tz).strftime(fmt)

return format_datetime


def create_engine(
config: Config,
site_root: Path | None = None,
Expand Down Expand Up @@ -41,10 +57,12 @@ def create_engine(

loaders.append(PackageLoader("rockgarden", "templates"))

return Environment(
env = Environment(
loader=ChoiceLoader(loaders),
autoescape=True,
)
env.filters["format_datetime"] = _make_format_datetime(config.site.timezone)
return env


def render_page(
Expand Down
2 changes: 1 addition & 1 deletion src/rockgarden/templates/components/footer.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<footer class="text-xs text-base-content/40 text-center py-6 mt-8 border-t border-base-200">
<div class="flex flex-col gap-1">
<div>Last built: {{ site.build_info.build_time.strftime('%m/%d/%Y %I:%M:%S %p UTC') }}</div>
<div>Last built: {{ site.build_info.build_time | format_datetime('%m/%d/%Y %I:%M:%S %p %Z') }}</div>
{% if site.build_info.git_commit %}
<div>Latest commit: &ldquo;{{ site.build_info.git_message }}&rdquo; by {{ site.build_info.git_author }} ({{ site.build_info.git_commit[:7] }})</div>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion src/rockgarden/templates/folder_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<a href="{{ child.path }}" class="link link-hover link-primary">{{ child.title }}</a>
{% endif %}
</td>
<td class="text-base-content/60 text-sm">{{ child.modified.strftime('%Y-%m-%d') if child.modified else '' }}</td>
<td class="text-base-content/60 text-sm">{{ child.modified | format_datetime }}</td>
<td>
{% if child.tags %}
<div class="flex flex-wrap gap-1">
Expand Down
6 changes: 3 additions & 3 deletions src/rockgarden/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
{% if page.created or page.modified or tags %}
<div class="text-sm text-base-content/50 -mt-4 mb-4 flex flex-wrap items-center gap-2">
{% if page.created and page.modified %}
<span>Created <time datetime="{{ page.created.strftime('%Y-%m-%d') }}">{{ page.created.strftime('%Y-%m-%d') }}</time> · Updated <time datetime="{{ page.modified.strftime('%Y-%m-%d') }}">{{ page.modified.strftime('%Y-%m-%d') }}</time></span>
<span>Created <time datetime="{{ page.created | format_datetime }}">{{ page.created | format_datetime }}</time> · Updated <time datetime="{{ page.modified | format_datetime }}">{{ page.modified | format_datetime }}</time></span>
{% elif page.modified %}
<time datetime="{{ page.modified.strftime('%Y-%m-%d') }}">{{ page.modified.strftime('%Y-%m-%d') }}</time>
<time datetime="{{ page.modified | format_datetime }}">{{ page.modified | format_datetime }}</time>
{% elif page.created %}
<span>Created <time datetime="{{ page.created.strftime('%Y-%m-%d') }}">{{ page.created.strftime('%Y-%m-%d') }}</time></span>
<span>Created <time datetime="{{ page.created | format_datetime }}">{{ page.created | format_datetime }}</time></span>
{% endif %}
{% if tags %}
<div class="flex flex-wrap gap-1">
Expand Down
11 changes: 11 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.