-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add post excerpt Liquid tag * add post excerpt as fallback
- Loading branch information
1 parent
6a85c30
commit 057bc43
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Jekyll | ||
# A simple tag for YouTube include using an iframe | ||
class ExcerptTag < Liquid::Tag | ||
def initialize(_tag_name, url, _tokens) | ||
super | ||
@article_id = url.strip | ||
end | ||
|
||
def render(context) | ||
posts = context.registers[:site].posts | ||
post = posts.docs.find {|doc| doc.id == @article_id} | ||
|
||
if !post.nil? | ||
title = post['title'] | ||
# one day figure out how to add author | ||
# author_id = post['author'] | ||
# author = context.registers[:site].data['authors'][author_id] | ||
# avatar = author['avatar'] | ||
# display_name = author['full_name'] | ||
description = post['description'] | ||
|
||
if (description.nil?) | ||
# Use excerpt in cases description doesn't exist. One day truncate text... | ||
description = post['excerpt'] | ||
end | ||
|
||
%(<article class="link-container" style="border: 1px solid silver; border-radius: 3px; padding: 12px 15px"> | ||
<a href='#{@article_id}' style="font-size: 1.375em; margin-bottom: 20px;"> | ||
<span>#{title}</span> | ||
</a> | ||
<p>#{description}</p> | ||
</article>) | ||
else | ||
%(<div class="link-container"> | ||
<a href='#{@article_id}'>Article not found!</a> | ||
</div>) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_tag('excerpt', Jekyll::ExcerptTag) |