Skip to content

Commit

Permalink
Add post excerpt Liquid tag (#1513)
Browse files Browse the repository at this point in the history
* Add post excerpt Liquid tag

* add post excerpt as fallback
  • Loading branch information
alisaduncan authored Jun 7, 2024
1 parent 6a85c30 commit 057bc43
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ Use the tweet ID from the Tweets URL

```

**Excerpt from OktaDev post**

Embed an OktaDev blog post within your post. You need to use the blog link format `/blog/YYYY/MM/DD/<keywords>`.

For example:

```markup
{% excerpt /blog/2024/02/29/net-scim %}
```

**StackBlitz**

This tag supports pre-created StackBlitz and auto-creating a StackBlitz directly from GitHub.
Expand Down
42 changes: 42 additions & 0 deletions _source/_plugins/excerpt.rb
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)

0 comments on commit 057bc43

Please sign in to comment.