Skip to content

Commit f1acdb2

Browse files
committed
example improvements
1 parent 659f98b commit f1acdb2

File tree

8 files changed

+17
-17
lines changed

8 files changed

+17
-17
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ about: {body: "This is an awesome blog about me."}
8383

8484
In addition to the collected data, templates have access to the following properties:
8585

86-
- `rootPath` is a relative path to the root of the project — useful as a prefix for links in includes (e.g. `<%= rootPath %>/index.css`).
87-
- `root` references all of the project's data, which is useful for accessing data outside of the current template's folder.
86+
- `rootPath` is a relative path to the root of the project — useful as a prefix for links in includes as they may be used on different nesting levels (e.g. `<%= rootPath %>/index.css`).
87+
- `root` references all of the project's data, which is useful for accessing data in includes or outside of the current template's folder.
8888

8989
## FAQ
9090

example/_footer.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<hr>
2-
<p>(c) 2020, Vladimir Agafonkin</p>
2+
<p>(c) 2020, <%= root.data.author %></p>
33
</div>
44
</body>
55
</html>

example/_header.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>tinyjam blog example</title>
4+
<title><%= root.data.title %></title>
55
<meta charset="utf-8">
66
<link rel="stylesheet" href="<%= rootPath %>/index.css">
77
</head>

example/data.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: tinyjam example
2+
author: Vladimir Agafonkin

example/index.ejs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<%- include('_header.ejs') -%>
22

3-
<h1>tinyjam example</h1>
3+
<h1><%= data.title %></h1>
44

5-
<% const names = Object.keys(posts).sort((a, b) => posts[b].date - posts[a].date); -%>
6-
<ul>
7-
<% for (const name of names) { const {date, title} = posts[name]; -%>
8-
<li><%= date.toDateString() %>: <a href="posts/<%= name %>.html"><%= title %></a></li>
5+
<% for (const name of Object.keys(posts).reverse()) { const {date, title, body} = posts[name]; -%>
6+
<h3><a href="posts/<%= name %>.html"><%= title %></a><%= date.toDateString() %></h3>
7+
<p><%- body.trim().match(/\<p>(.+)<\/p>/)[1] %> [&hellip;]</p>
98
<% } -%>
10-
</ul>
119

1210
<%- include('_footer.ejs') -%>

test/fixtures/example_output/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>tinyjam blog example</title>
4+
<title>tinyjam example</title>
55
<meta charset="utf-8">
66
<link rel="stylesheet" href="./index.css">
77
</head>
@@ -10,10 +10,10 @@
1010

1111
<h1>tinyjam example</h1>
1212

13-
<ul>
14-
<li>Sat May 09 2020: <a href="posts/02.html">Another post</a></li>
15-
<li>Fri May 08 2020: <a href="posts/01.html">Hello tinyjam</a></li>
16-
</ul>
13+
<h3><a href="posts/02.html">Another post</a> — Sat May 09 2020</h3>
14+
<p>Cras a dolor sit amet ipsum fermentum tincidunt ut vel est. Duis mattis tortor eget diam tempus, nec facilisis urna sollicitudin. Etiam neque quam, pulvinar in dapibus in, malesuada at ante. Suspendisse sed risus blandit, dapibus felis a, porttitor ligula. Suspendisse tempus nec tortor quis molestie. [&hellip;]</p>
15+
<h3><a href="posts/01.html">Hello tinyjam</a> — Fri May 08 2020</h3>
16+
<p>Hello world! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer at odio consequat, suscipit elit at, gravida est. Duis sodales ornare diam, eget tristique libero porttitor sed. Donec id orci nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. [&hellip;]</p>
1717

1818
<hr>
1919
<p>(c) 2020, Vladimir Agafonkin</p>

test/fixtures/example_output/posts/01.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>tinyjam blog example</title>
4+
<title>tinyjam example</title>
55
<meta charset="utf-8">
66
<link rel="stylesheet" href="../index.css">
77
</head>

test/fixtures/example_output/posts/02.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>tinyjam blog example</title>
4+
<title>tinyjam example</title>
55
<meta charset="utf-8">
66
<link rel="stylesheet" href="../index.css">
77
</head>

0 commit comments

Comments
 (0)