aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--NOTE.md2
-rw-r--r--lib/command.rb91
-rw-r--r--lib/parser.rb5
-rw-r--r--templates/document__post.html.erb9
-rw-r--r--templates/document__post_list.html.erb (renamed from templates/tag.html.erb)23
-rw-r--r--templates/document__tag.html.erb (renamed from templates/posts_list.html.erb)23
6 files changed, 88 insertions, 65 deletions
diff --git a/NOTE.md b/NOTE.md
index 8cc3a17..dd60fbd 100644
--- a/NOTE.md
+++ b/NOTE.md
@@ -48,7 +48,7 @@ $ touch content/posts/$(date +'%Y-%m-%d')/[TITLE].md
* https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap?hl=ja
* [ ] Admonitions
* [x] Stylesheet cache busting
-* [ ] templates
+* [x] templates
* Define custom converter using ERB
diff --git a/lib/command.rb b/lib/command.rb
index 5662eec..dc2561a 100644
--- a/lib/command.rb
+++ b/lib/command.rb
@@ -12,9 +12,6 @@ module NulDoc
'author' => @config[:author],
'site-copyright-year' => @config[:site_copyright_year],
'site-name' => @config[:site_name],
- 'source-highlighter' => 'rouge',
- 'reproducible' => true,
- 'sectids' => false,
},
@content_dir,
@template_dir,
@@ -24,7 +21,7 @@ module NulDoc
def run
posts = generate_posts(@content_dir + '/posts')
generate_tags(posts)
- generate_posts_list(posts)
+ generate_post_list(posts)
end
private
@@ -94,18 +91,32 @@ module NulDoc
end
def build_tag_doc(tag, posts)
- erb = ERB.new(File.read(@template_dir + '/tag.html.erb'), trim_mode: '<>')
- erb.result_with_hash({
- stylesheets: stylesheets,
- tag: tag,
- posts: posts,
- author: @config[:author],
- site_copyright_year: @config[:site_copyright_year],
- site_name: @config[:site_name],
- lang: 'ja-JP', # TODO
- copyright_year: posts.last.attributes['revision-history'].first.date.year,
- description: "タグ「#{tag.label}」のついた記事一覧",
- })
+ converter = NulDoc::HTMLConverter.new(nil, { template_dirs: [@template_dir] })
+ converter.convert_document(
+ (Class.new do
+ def initialize(config, tag, posts, stylesheets)
+ @config = config
+ @tag = tag
+ @posts = posts
+ @stylesheets = stylesheets
+ end
+ def attr(name)
+ case name
+ when 'document-type'; 'tag'
+ when 'stylesheets'; @stylesheets
+ when 'author'; @config[:author]
+ when 'site-copyright-year'; @config[:site_copyright_year]
+ when 'site-name'; @config[:site_name]
+ when 'lang'; 'ja-JP' # TODO
+ when 'copyright-year'; @posts.last.attributes['revision-history'].first.date.year
+ when 'description'; "タグ「#{@tag.label}」のついた記事一覧"
+ else raise "Unknown attr: #{name}"
+ end
+ end
+ def title; @tag.label; end
+ def posts; @posts; end
+ end).new(@config, tag, posts, stylesheets)
+ )
end
def output_tags(tag_docs)
@@ -121,28 +132,40 @@ module NulDoc
end
end
- def generate_posts_list(posts)
- html = build_posts_list_doc(posts)
- output_posts_list(html)
+ def generate_post_list(posts)
+ html = build_post_list_doc(posts)
+ output_post_list(html)
end
- def build_posts_list_doc(posts)
- erb = ERB.new(File.read(@template_dir + '/posts_list.html.erb'), trim_mode: '<>')
- erb.result_with_hash({
- stylesheets: stylesheets,
- posts: posts.reverse,
- author: @config[:author],
- site_copyright_year: @config[:site_copyright_year],
- site_name: @config[:site_name],
- lang: 'ja-JP', # TODO
- copyright_year: @config[:site_copyright_year],
- description: "記事一覧",
- doctitle: "Posts",
- header_title: "Posts",
- })
+ def build_post_list_doc(posts)
+ converter = NulDoc::HTMLConverter.new(nil, { template_dirs: [@template_dir] })
+ converter.convert_document(
+ (Class.new do
+ def initialize(config, posts, stylesheets)
+ @config = config
+ @posts = posts
+ @stylesheets = stylesheets
+ end
+ def attr(name)
+ case name
+ when 'document-type'; 'post_list'
+ when 'stylesheets'; @stylesheets
+ when 'author'; @config[:author]
+ when 'site-copyright-year'; @config[:site_copyright_year]
+ when 'site-name'; @config[:site_name]
+ when 'lang'; 'ja-JP' # TODO
+ when 'copyright-year'; @config[:site_copyright_year]
+ when 'description'; '記事一覧'
+ else raise "Unknown attr: #{name}"
+ end
+ end
+ def title; 'Posts'; end
+ def posts; @posts; end
+ end).new(@config, posts.reverse, stylesheets)
+ )
end
- def output_posts_list(html)
+ def output_post_list(html)
destination_file_path = "#{@dest_dir}/posts/index.html"
destination_dir = File.dirname(destination_file_path)
unless Dir.exist?(destination_dir)
diff --git a/lib/parser.rb b/lib/parser.rb
index e644dc6..f241c4d 100644
--- a/lib/parser.rb
+++ b/lib/parser.rb
@@ -17,9 +17,12 @@ module NulDoc
template_engine: 'erb',
template_engine_options: { erb: { trim: '<>' } },
attributes: @common_attributes.merge({
+ 'document-type' => document_type,
'source-file-path' => file_path,
'href' => file_path.sub(@content_dir, '').sub('.adoc', '/'),
- 'document-type' => document_type,
+ 'source-highlighter' => 'rouge',
+ 'reproducible' => true,
+ 'sectids' => false,
}),
extension_registry: Asciidoctor::Extensions.create do
tree_processor Nuldoc::Extensions::RevisionHistoryProcessor
diff --git a/templates/document__post.html.erb b/templates/document__post.html.erb
index bc9a842..a52ac9a 100644
--- a/templates/document__post.html.erb
+++ b/templates/document__post.html.erb
@@ -4,11 +4,10 @@
<% _lang = attr 'lang' %>
<% _site_copyright_year = attr 'site-copyright-year' %>
<% _copyright_year = attr 'copyright-year' %>
-<% _revisions = attr 'revision-history' %>
<% _site_name = attr 'site-name' %>
+<% _title = title %>
+<% _revisions = attr 'revision-history' %>
<% _tags = attr 'tags' %>
-<% _doctitle = doctitle %>
-<% _header_title = header.title %>
<% _content = content %>
<!DOCTYPE html>
<html lang="<%= _lang %>">
@@ -20,7 +19,7 @@
<meta name="description" content="<%= _description %>">
<meta name="keywords" content="<%= _tags.map(&:label).join(',') %>">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
- <title><%= _doctitle %> | <%= _site_name %></title>
+ <title><%= _title %> | <%= _site_name %></title>
<% for stylesheet in _stylesheets %>
<link rel="stylesheet" href="<%= stylesheet %>">
<% end %>
@@ -36,7 +35,7 @@
<main class="main">
<article class="post-single">
<header class="post-header">
- <h1 class="post-title"><%= _header_title %></h1>
+ <h1 class="post-title"><%= _title %></h1>
<% if not _tags.empty? %>
<ul class="post-tags">
<% for tag in _tags %>
diff --git a/templates/tag.html.erb b/templates/document__post_list.html.erb
index c92c0ca..c1429ec 100644
--- a/templates/tag.html.erb
+++ b/templates/document__post_list.html.erb
@@ -1,12 +1,11 @@
-<% _stylesheets = stylesheets %>
-<% _author = author %>
-<% _description = description %>
-<% _lang = lang %>
-<% _site_copyright_year = site_copyright_year %>
-<% _copyright_year = copyright_year %>
-<% _site_name = site_name %>
-<% _doctitle = tag.label %>
-<% _header_title = tag.label %>
+<% _stylesheets = attr 'stylesheets' %>
+<% _author = attr 'author' %>
+<% _description = attr 'description' %>
+<% _lang = attr 'lang' %>
+<% _site_copyright_year = attr 'site-copyright-year' %>
+<% _copyright_year = attr 'copyright-year' %>
+<% _site_name = attr 'site-name' %>
+<% _title = title %>
<% _posts = posts %>
<!DOCTYPE html>
<html lang="<%= _lang %>">
@@ -17,7 +16,7 @@
<meta name="copyright" content="&copy; <%= _copyright_year %> <%= _author %>">
<meta name="description" content="<%= _description %>">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
- <title><%= _doctitle %> | <%= _site_name %></title>
+ <title><%= _title %> | <%= _site_name %></title>
<% for stylesheet in _stylesheets %>
<link rel="stylesheet" href="<%= stylesheet %>">
<% end %>
@@ -26,13 +25,13 @@
<header class="header">
<nav class="nav">
<p class="logo">
- <a href="/">REPL: Rest-Eat-Program Loop</a>
+ <a href="/"><%= _site_name %></a>
</p>
</nav>
</header>
<main class="main">
<header class="page-header">
- <h1><%= _header_title %></h1>
+ <h1><%= _title %></h1>
</header>
<% for post in _posts %>
<article class="post-entry">
diff --git a/templates/posts_list.html.erb b/templates/document__tag.html.erb
index 5367258..c1429ec 100644
--- a/templates/posts_list.html.erb
+++ b/templates/document__tag.html.erb
@@ -1,12 +1,11 @@
-<% _stylesheets = stylesheets %>
-<% _author = author %>
-<% _description = description %>
-<% _lang = lang %>
-<% _site_copyright_year = site_copyright_year %>
-<% _copyright_year = copyright_year %>
-<% _site_name = site_name %>
-<% _doctitle = doctitle %>
-<% _header_title = header_title %>
+<% _stylesheets = attr 'stylesheets' %>
+<% _author = attr 'author' %>
+<% _description = attr 'description' %>
+<% _lang = attr 'lang' %>
+<% _site_copyright_year = attr 'site-copyright-year' %>
+<% _copyright_year = attr 'copyright-year' %>
+<% _site_name = attr 'site-name' %>
+<% _title = title %>
<% _posts = posts %>
<!DOCTYPE html>
<html lang="<%= _lang %>">
@@ -17,7 +16,7 @@
<meta name="copyright" content="&copy; <%= _copyright_year %> <%= _author %>">
<meta name="description" content="<%= _description %>">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
- <title><%= _doctitle %> | <%= _site_name %></title>
+ <title><%= _title %> | <%= _site_name %></title>
<% for stylesheet in _stylesheets %>
<link rel="stylesheet" href="<%= stylesheet %>">
<% end %>
@@ -26,13 +25,13 @@
<header class="header">
<nav class="nav">
<p class="logo">
- <a href="/">REPL: Rest-Eat-Program Loop</a>
+ <a href="/"><%= _site_name %></a>
</p>
</nav>
</header>
<main class="main">
<header class="page-header">
- <h1><%= _header_title %></h1>
+ <h1><%= _title %></h1>
</header>
<% for post in _posts %>
<article class="post-entry">