Skip to content

Commit

Permalink
Added ability to render "Has more" link.
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed Apr 29, 2024
1 parent 196fee8 commit 8f9f270
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/difference-from-coleslaw.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The `site.sitenav` list was renamed to `site.navigation.items`. Also items insid
## Index pages
For index pages a list of items was also moved and now instead of `index.content` a `content.items` should be used.
For index pages a list of items was also moved and now instead of `index.content` a `content.items` should be used. Usually index pages render only the beginning of the post and by default this introduction is separated by `<!--more-->` line. Staticl makes it possible to render a link \"Read more\" by providing an `obj.has_more` flag, which will be set to `T` if the separator is present in the post's body.
### Index objects
Expand Down
6 changes: 6 additions & 0 deletions src/content.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
(:import-from #:staticl/current-root
#:current-root)
(:import-from #:staticl/content/html-content
#:has-more-content-p
#:content-html-excerpt
#:content-html)
(:import-from #:staticl/clean-urls
Expand Down Expand Up @@ -350,6 +351,11 @@
(to-html excerpt
(content-format content))))

(defmethod has-more-content-p ((content content-from-file))
(let* ((separator (content-excerpt-separator content))
(full-content (content-text content)))
(str:containsp separator full-content)))


(defmethod template-vars ((site site) (content content-from-file) &key (hash (dict)))
(setf (gethash "title" hash)
Expand Down
6 changes: 5 additions & 1 deletion src/content/html-content.lisp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(uiop:define-package #:staticl/content/html-content
(:use #:cl)
(:export #:content-html
#:content-html-excerpt))
#:content-html-excerpt
#:has-more-content-p))
(in-package #:staticl/content/html-content)


Expand All @@ -10,3 +11,6 @@

(defgeneric content-html-excerpt (content)
(:documentation "Returns an excerpt of full content as HTML string."))

(defgeneric has-more-content-p (content)
(:documentation "Returns T if there is more content than was returned by CONTENT-HTML-EXCERPT generic-function."))
4 changes: 3 additions & 1 deletion src/index/base.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@
"created-at"
(staticl/content:content-created-at item)
"excerpt"
(staticl/content/html-content:content-html-excerpt item))))
(staticl/content/html-content:content-html-excerpt item)
"has-more"
(staticl/content/html-content:has-more-content-p item))))
(declare (dynamic-extent #'item-vars))

(setf (gethash "title" hash)
Expand Down
1 change: 1 addition & 0 deletions themes/hyde/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<a class="article-title" href="{$obj.url}">{$obj.title}</a>
<div class="date"> posted on {$obj.created_at | date}</div>
<div class="article">{$obj.excerpt |noAutoescape}</div>
{if $obj.has_more}<p><a href="{$obj.url}">Read more...</a></p>{/if}
</div>
{/foreach}
<div id="relative-nav">
Expand Down
4 changes: 2 additions & 2 deletions themes/hyde/post.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<h1 class="title">{$content.title}</h1>{\n}
<div class="tags">{\n}
{if $content.tags}
Tagged as {foreach $tag in $content.tags}
<a href="{$tag.url}">{$tag.name}</a>{nil}
Tagged as {foreach $tag in $content.tags}
{if $tag.url}<a href="{$tag.url}">{$tag.name}</a>{else}<b>{$tag.name}</b>{/if}{nil}
{if not isLast($tag)},{sp}{/if}
{/foreach}
{/if}
Expand Down

0 comments on commit 8f9f270

Please sign in to comment.