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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

## main

- [ADD] tag ページ生成機能 (仮) を追加する
- 実験的機能であるため、破壊的変更が行われる可能性があることに注意
- @zztkm

## v0.17.0

- [ADD] 設定に `build.markdown.allow_dangerous_html` を追加する
Expand Down
10 changes: 10 additions & 0 deletions example_site/layouts/posts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ <h1>{{site_title}}</h1>
<main>
{{{contents}}}
</main>
{{#has_tags}}
<div class="tags-section">
<h3>Tags</h3>
<ul class="tag-list">
{{#tags}}
<li><a href="{{url}}" class="tag-link">{{name}}</a></li>
{{/tags}}
</ul>
</div>
Comment on lines +20 to +27
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

現在の実装では、投稿にタグがない場合でも「Tags」という見出しと空のリスト(<ul>)が表示されてしまいます。
ramhornsテンプレートでは、リストが空でない場合にのみブロックをレンダリングする機能があります。このセクション全体を条件ブロックで囲むことで、タグが存在する場合にのみ表示されるように修正することをお勧めします。

この修正を有効にするには、バックエンドのRenderContext構造体のtagsフィールドをVec<Tag>からOption<Vec<Tag>>に変更する必要があります。そして、タグのリストが空の場合はNoneを、そうでない場合はSome(tags)をコンテキストに渡してください。ramhornsOptionを正しく解釈し、Someの場合のみブロックをレンダリングします。

テンプレートの修正案は以下の通りです。{{#tags}}Optionをチェックし、{{#.}}Vecをイテレートします。

    {{#tags}}
    <div class="tags-section">
        <h3>Tags</h3>
        <ul class="tag-list">
            {{#.}}
            <li><a href="{{url}}" class="tag-link">{{name}}</a></li>
            {{/.}}
        </ul>
    </div>
    {{/tags}}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正した

{{/has_tags}}
<footer>
<p>&copy; 2025 {{site_title}}</p>
{{#author}}
Expand Down
36 changes: 36 additions & 0 deletions example_site/layouts/tags/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Posts tagged "{{tag_name}}" - {{site_title}}</title>
<meta name="description" content="{{site_description}}">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<header>
<h1>{{site_title}}</h1>
<p>{{site_description}}</p>
</header>
<main>
<h1>Posts tagged "{{tag_name}}"</h1>

<ul class="post-list">
{{#posts}}
<li class="post-item">
<h2><a href="{{url}}">{{title}}</a></h2>
{{#pub_datetime}}
<p class="post-meta"><time datetime="{{pub_datetime}}">{{pub_datetime}}</time>{{#author}} by {{author}}{{/author}}</p>
{{/pub_datetime}}
{{#description}}
<p class="post-description">{{description}}</p>
{{/description}}
</li>
{{/posts}}
</ul>
</main>
<footer>
<p>&copy; 2025 {{site_title}}</p>
</footer>
</body>
</html>
1 change: 0 additions & 1 deletion example_site/posts/first.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ description: My first blog post
author: zztkm
pub_datetime: 2024-11-08
post_slug: first-post
tags: ["blog", "example"]
---

# First Post
Expand Down
14 changes: 14 additions & 0 deletions example_site/posts/second.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Second Post
description: Another example blog post
author: zztkm
pub_datetime: 2024-11-10
post_slug: second-post
tags: ["blog", "tutorial"]
---

# Second Post

This is another example post demonstrating multiple tags.

Posts with tags will appear on multiple tag pages.
83 changes: 83 additions & 0 deletions example_site/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,86 @@ footer {
color: #666;
font-size: 0.9em;
}

/* タグ表示 */
.tags-section {
margin-top: 40px;
padding-top: 20px;
border-top: 1px solid #eee;
}

.tags-section h3 {
font-size: 1.2em;
margin-bottom: 12px;
color: #666;
}

.tag-list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
gap: 8px;
}

.tag-list li {
margin: 0;
}

.tag-link {
display: inline-block;
padding: 4px 12px;
background-color: #007acc;
color: white;
text-decoration: none;
border-radius: 4px;
font-size: 0.9em;
transition: background-color 0.2s;
}

.tag-link:hover {
background-color: #005a9e;
}

/* タグページの投稿一覧 */
.post-list {
list-style: none;
margin: 0;
padding: 0;
}

.post-item {
margin-bottom: 32px;
padding-bottom: 24px;
border-bottom: 1px solid #eee;
}

.post-item:last-child {
border-bottom: none;
}

.post-item h2 {
margin-top: 0;
margin-bottom: 8px;
}

.post-item h2 a {
color: #007acc;
text-decoration: none;
}

.post-item h2 a:hover {
text-decoration: underline;
}

.post-meta {
color: #666;
font-size: 0.9em;
margin-bottom: 8px;
}

.post-description {
color: #555;
line-height: 1.6;
}
12 changes: 12 additions & 0 deletions example_site/vss.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ ignore_files = ["README.md"]
# この設定が false だとコメントアウトは文字列として処理されてしまいます
allow_dangerous_html = false

[build.tags]
# タグページ生成を有効化(デフォルト: true)
enable = true

# 使用するテンプレート(デフォルト: "tags/default.html")
template = "tags/default.html"

# タグページのURLパターン(デフォルト: "/tags/{tag}/")
# {tag} はタグ名に置き換えられます
# このパターンが出力先とURLの両方を決定します
url_pattern = "/tags/{tag}/"

Loading