mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +00:00
Clean up post templates with "include"
This commit is contained in:
parent
09e45c9617
commit
085949bd87
9 changed files with 20 additions and 102 deletions
|
|
@ -128,17 +128,12 @@ final class PostsPlugin: Plugin {
|
|||
try fileManager.createDirectory(at: monthDir, withIntermediateDirectories: true, attributes: nil)
|
||||
let filename = "\(post.slug).html"
|
||||
let postURL = monthDir.appendingPathComponent(filename)
|
||||
let templateName = self.templateName(for: post)
|
||||
let bodyHTML = markdownParser.html(from: post.bodyMarkdown)
|
||||
let renderedPost = RenderedPost(post: post, body: bodyHTML)
|
||||
let postHTML = try templateRenderer.renderTemplate(name: templateName, context: ["post": renderedPost.dictionary])
|
||||
let postHTML = try templateRenderer.renderTemplate(name: "post", context: ["post": renderedPost.dictionary])
|
||||
try postHTML.write(to: postURL, atomically: true, encoding: .utf8)
|
||||
}
|
||||
|
||||
private func templateName(for post: Post) -> String {
|
||||
post.isLink ? "post-link" : "post-text"
|
||||
}
|
||||
|
||||
private func enumerateMarkdownFiles(directory: URL) throws -> [URL] {
|
||||
return try fileManager.contentsOfDirectory(atPath: directory.path).flatMap { (filename: String) -> [URL] in
|
||||
let fileURL = directory.appendingPathComponent(filename)
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
HANDLED {% if post.link %} -%>
|
||||
<article class="container">
|
||||
<header>
|
||||
<h1><a href="<%= post.link %>">→ <%= post.title %></a></h1>
|
||||
<time><%= post.date %></time>
|
||||
<a class="permalink" href="<%= post.url %>">∞</a>
|
||||
</header>
|
||||
<%- yield %>
|
||||
</article>
|
||||
<div class="row clearfix">
|
||||
<p class="fin clearfix"><i class="fa fa-code"></i></p>
|
||||
</div>
|
||||
HANDLED <% } else if (typeof date != 'undefined' && date !== null) { -%>
|
||||
<article class="container">
|
||||
<header>
|
||||
<h1><a href="<%= url %>"><%= title %></a></h1>
|
||||
<time><%= date %></time>
|
||||
</header>
|
||||
<%- yield %>
|
||||
</article>
|
||||
<div class="row clearfix">
|
||||
<p class="fin"><i class="fa fa-code"></i></p>
|
||||
</div>
|
||||
WTF IS THIS?? MUST BE PROJECTS! <% } else if (typeof title != 'undefined' && title !== null) { -%>
|
||||
<article class="container">
|
||||
<h1><%= title %></h1>
|
||||
<%- yield %>
|
||||
</article>
|
||||
<div class="row clearfix">
|
||||
<p class="fin"><i class="fa fa-code"></i></p>
|
||||
</div>
|
||||
HANDLED <% } else { -%>
|
||||
<%- yield %>
|
||||
<% } -%>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
{% extends "samhuri.net.html" %}
|
||||
|
||||
{% block body %}
|
||||
<article class="container">
|
||||
<h1>{{ page.title }}</h1>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
{% extends "samhuri.net.html" %}
|
||||
|
||||
{% block body %}
|
||||
<article class="container">
|
||||
<header>
|
||||
<h1><a href="{{ post.link }}">→ {{ post.title }}</a></h1>
|
||||
<time>{{ post.formattedDate }}</time>
|
||||
<a class="permalink" href="{{ post.url }}">∞</a>
|
||||
<a class="permalink" href="{{ post.path }}">∞</a>
|
||||
</header>
|
||||
{{ post.body }}
|
||||
</article>
|
||||
<div class="row clearfix">
|
||||
<p class="fin clearfix"><i class="fa fa-code"></i></p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -1,6 +1,3 @@
|
|||
{% extends "samhuri.net.html" %}
|
||||
|
||||
{% block body %}
|
||||
<article class="container">
|
||||
<header>
|
||||
<h1><a href="{{ post.path }}">{{ post.title }}</a></h1>
|
||||
|
|
@ -11,4 +8,3 @@
|
|||
<div class="row clearfix">
|
||||
<p class="fin"><i class="fa fa-code"></i></p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
5
templates/partial-post.html
Normal file
5
templates/partial-post.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{% if post.isLink %}
|
||||
{% include "partial-post-link.html" %}
|
||||
{% else %}
|
||||
{% include "partial-post-text.html" %}
|
||||
{% endif %}
|
||||
5
templates/post.html
Normal file
5
templates/post.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{% extends "samhuri.net.html" %}
|
||||
|
||||
{% block body %}
|
||||
{% include "partial-post.html" %}
|
||||
{% endblock %}
|
||||
|
|
@ -2,23 +2,6 @@
|
|||
|
||||
{% block body %}
|
||||
{% for post in posts %}
|
||||
<article class="container">
|
||||
<header>
|
||||
{% if post.isLink %}
|
||||
<h2><a href="{{ post.link }}">→ {{ post.title }}</a></h2>
|
||||
<time>{{ post.formattedDate }}</time>
|
||||
<a class="permalink" href="{{ post.path }}">∞</a>
|
||||
{% else %}
|
||||
<h2><a href="{{ post.path }}">{{ post.title }}</a></h2>
|
||||
<time>{{ post.formattedDate }}</time>
|
||||
{% endif %}
|
||||
</header>
|
||||
|
||||
{{ post.body }}
|
||||
</article>
|
||||
<div class="row clearfix">
|
||||
<p class="fin"><i class="fa fa-code"></i></p>
|
||||
</div>
|
||||
|
||||
{% include "partial-post.html" post %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,9 @@
|
|||
{% extends "samhuri.net.html" %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<% var posts = public._data.posts -%>
|
||||
<% for (var i in posts) { -%>
|
||||
|
||||
<% var post = posts[i] -%>
|
||||
|
||||
<% if (post.link) { -%>
|
||||
|
||||
<article>
|
||||
<header>
|
||||
<h2><a href="<%= post.link %>"><%= post.title %></a></h2>
|
||||
<time><%= post.date %></time>
|
||||
</header>
|
||||
<%- partial(post.url) %>
|
||||
<p><a class="permalink" href="<%= post.url %>">∞</a></p>
|
||||
</article>
|
||||
|
||||
<% } else { -%>
|
||||
|
||||
<article>
|
||||
<header>
|
||||
<h2><a href="<%= post.url %>"><%= post.title %></a></h2>
|
||||
<time><%= post.date %></time>
|
||||
</header>
|
||||
<%- partial(post.url) %>
|
||||
</article>
|
||||
|
||||
<% } -%>
|
||||
|
||||
<div class="row clearfix">
|
||||
<p class="fin"><i class="fa fa-code"></i></p>
|
||||
</div>
|
||||
|
||||
<% } -%>
|
||||
{% for post in recentPosts %}
|
||||
{% include "partial-post.html" post %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue