Skip to content

Commit 7778788

Browse files
flynnduismmichelleN
authored andcommitted
adding the blog listing template and rhai
Signed-off-by: Ronan Flynn-Curran <[email protected]>
1 parent acf8b58 commit 7778788

File tree

5 files changed

+72
-14
lines changed

5 files changed

+72
-14
lines changed

content/blog/hello.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
title = "HELLO WORLD"
2-
date = "2025-10-30T15:20:11.486765Z"
2+
date = "2025-10-30T12:00:00Z"
33
template = "blog"
4-
tags = []
54

65
[extra]
76
author = "Michelle Dhanani"

content/blog/index.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
title = "blog"
2-
template = "blog"
3-
date = "2025-10-29T00:22:56Z"
4-
content_type = "application/json"
1+
title = "Spin | Community Blog"
2+
template = "main"
3+
date = "2022-04-01T00:00:00Z"
4+
5+
[extra]
6+
author = "Spin Community"
7+
type = "index"
8+
category = "index"
59

610
---

scripts/blogs.rhai

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// This function lists all of the blog posts, subject to the constraints.
2+
//
3+
// It returns an array of objects of the form:
4+
// [
5+
// #{
6+
// uri: "path/to/page",
7+
// page: {
8+
// head: {title: "some title", description: "Some description", ...}
9+
// body: "This is the HTML"
10+
// }
11+
// }
12+
// ]
13+
//
14+
// The array is sorted with the earlier items being most recent, and the oldest items at the end.
15+
16+
// Param 1 should be `site.pages`
17+
let pages = params[0];
18+
19+
// Loop through them and return all of the page objects that are in
20+
// the blog path.
21+
22+
let blog_pages = [];
23+
24+
// Get each blog post, assigning it to {path: object}.
25+
let keys = pages.keys();
26+
for item in keys {
27+
if item.index_of("/content/blog/") == 0 && pages[item].head.extra.type == "post" {
28+
// Remove /content and .md
29+
let path = item.sub_string(8);
30+
let page = pages[item];
31+
path = path.sub_string(0, path.index_of(".md"));
32+
33+
blog_pages.push(#{
34+
uri: path,
35+
page: page,
36+
template: "blog",
37+
});
38+
//blog_pages[path] = pages[item];
39+
}
40+
41+
}
42+
43+
// Return the blogs sorted newest to oldest
44+
fn sort_by_date(a, b) {
45+
if a.page.head.date < b.page.head.date {
46+
1
47+
} else {
48+
-1
49+
}
50+
}
51+
52+
// Sort by the value of the page date.
53+
blog_pages.sort(Fn("sort_by_date"));
54+
55+
blog_pages

templates/content_navbar.hbs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616
<div class="navbar-menu">
1717
<div class="navbar-start">
1818

19-
<a class="navbar-item plausible-event-name=docs-nav navbar-stack" href="/blog" title="Spin community blog">
20-
<strong>Community Blog</strong>
21-
<small>Stay up to date on latest with Spin</small>
22-
19+
<a class="navbar-item plausible-event-name=docs-nav navbar-stack" href="/docs" title="Spin Documentation">
20+
<strong>Docs</strong>
21+
<small>Get started building Wasm apps with Spin</small>
2322
</a>
2423

2524
<a class="navbar-item plausible-event-name=docs-nav-hub navbar-stack" href="/hub" title="Sample apps, plugins and templates in Spin Hub">
2625
<strong>Spin Hub</strong>
2726
<small>Browse example app code and templates</small>
2827
</a>
2928

29+
<a class="navbar-item plausible-event-name=docs-nav navbar-stack" href="/blog/index" title="Spin Community Blog">
30+
<strong>Community Blog</strong>
31+
<small>Stay up to date on Spin releases</small>
32+
</a>
33+
3034
{{!-- <a class="navbar-item plausible-event-name=docs-nav-blog navbar-stack" href="/blog" title="Sample apps, plugins and templates in Spin Hub">
3135
<strong>Blog</strong>
3236
<small>Latest community posts about Spin</small>

templates/main.hbs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,3 @@
4646

4747
{{! This closes the body. See content_bottom.hbs. }}
4848
{{> content_bottom }}
49-
50-
</body>
51-
52-
</html>

0 commit comments

Comments
 (0)