Skip to content

Commit

Permalink
#14 add more content
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten Marx committed Oct 25, 2023
1 parent 0c3dd81 commit 112c916
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hosts/demo/content/installation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Default markdown engine is _flexmark_.
hostname: localhost
template:
engine: thymeleaf
markdownd:
markdown:
engine: flexmark
```
Expand Down
6 changes: 4 additions & 2 deletions hosts/demo/content/templating/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Templates & Engines
template: start.html
template: content.html
menu:
title: Templating
position: 20
Expand All @@ -12,4 +12,6 @@ Aktuell kann zwischen folgenden TemplateEngines zur Verfügung.

* [Thymeleaf](https://thymeleaf.org)
* [Pebble](https://pebbletemplates.io/)
* [Apache Freemarker](https://freemarker.apache.org/)
* [Apache Freemarker](https://freemarker.apache.org/)

For information about configuration of template engien to be used see the [per host config](/installation#per-host-config)
17 changes: 17 additions & 0 deletions hosts/demo/content/templating/index.part.01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Navigation
template: content.part.html
---

Navigation is realy simple.

```html
<ul th:with="nodes=${navigation.list('/')}">
<li th:each="node : ${nodes}" th:if="${node.path} != '/'">
<a th:attr="aria-current=${node.current ? 'page' : ''}"
th:classappend="${node.current}? 'active'"
th:href="${node.path}"
th:text="${node.name}"></a>
</li>
</ul>
```
35 changes: 35 additions & 0 deletions hosts/demo/content/templating/index.part.02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: List of pages
template: content.part.html
---

Whenever you want to print out a list of pages, the nodeListFunction is a tiny little helper.
Keep in mind, that the nodelist function does not return the hole rendered HTML content but just an excerpt of 200 characters.

```html
<!-- example for a blog overview page -->
<div
th:with='page = ${nodeList.from("/blog/*").sort("published").reverse(true).page(1).size(5).list()}'>
<th:block th:each="entry : ${page.items}">
<h2 th:text="${entry.name}"></h2>
<p th:text="${entry.content}"></p>
<u th:text="${#dates.format(entry.meta['published'], 'dd-MM-yyyy HH:mm')}"></u>
<a th:href="${entry.path}">goto</a>
</th:block>
</div>
```

#### UseCase Blog
Assume, your project has the following content structure for the blog, with the defaults _page = 1_ and _pageSize = 5_
```
blog/
---2023-09/
------entry1.md
------entry2.md
---2023-10/
------entry1.md
```
This nodeList call will return all content nodes in all subfolders of the folder blog/
```javascript
${nodeList.from("/blog/*").list()}
```
2 changes: 1 addition & 1 deletion hosts/demo/templates/content.part.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<div class="card-body">
<h5 class="card-title" th:text="${meta.title}"></h5>
<p class="card-text" th:utext="${content}"></p>
<a href="#" class="card-link">readmore</a>
<!--a href="#" class="card-link">readmore</a-->
</div>
</div>
2 changes: 1 addition & 1 deletion hosts/demo/templates/libs/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarScroll">
<ul th:with="nodes=${navigation.list('/', 0)}" class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll"
<ul th:with="nodes=${navigation.list('/')}" class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll"
style="--bs-scroll-height: 100px;">
<li th:each="node : ${nodes}" th:if="${node.path} != '/'" class="nav-item">
<a th:attr="aria-current=${node.current ? 'page' : ''}"
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<artifactId>flexmark-ext-tables</artifactId>
<version>0.64.8</version>
</dependency>
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-ext-anchorlink</artifactId>
<version>0.64.8</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension;
import com.vladsch.flexmark.ext.tables.TablesExtension;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
Expand All @@ -40,7 +41,8 @@ public class FlexMarkMarkdownRenderer implements MarkdownRenderer {

public FlexMarkMarkdownRenderer () {
options.set(Parser.EXTENSIONS, List.of(
TablesExtension.create()
TablesExtension.create(),
AnchorLinkExtension.create()
));
parser = Parser.builder(options).build();
renderer = HtmlRenderer.builder(options).build();
Expand Down

0 comments on commit 112c916

Please sign in to comment.