Skip to content

Commit 8d55826

Browse files
committed
Added functionality for blogs to be part of a series
1 parent 3c8daa6 commit 8d55826

File tree

9 files changed

+66
-2
lines changed

9 files changed

+66
-2
lines changed

content/blog/entries/ssr-ccsearch/contents.lr

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
title: Server Side Rendering with Vue.JS on CC Search
22
---
33
categories:
4+
45
cc-search
56
tech
67
---
@@ -9,7 +10,7 @@ author: brenoferreira
910
pub_date: 2019-11-01
1011
---
1112
body:
12-
13+
1314
The frontend of CC Search is built with Vue.JS, which is a Javascript library for managing and rendering DOM elements in the browser, similar to React and Angular. But, as it is usually the case with applications built with those libraries, the application was rendered completely on the users' browser. It means that when users loaded CC Search, the server would send a blank HTML page and some Javascript files that would be downloaded by the user. Only once those JS assets were loaded and parsed, would the rendering begin.
1415

1516
While easier to implement initially, when we needed to ship the initial versions of CC Search faster to validate our ideas, this approach has some significant disadvantages:
@@ -89,3 +90,5 @@ We did this by using the `serverPrefetch` method to load the data on the server,
8990
As said before, we have a dependency on a component that uses browser APIs which doesn't work on the server side. That dependency is [Masonry Layout](https://github.com/shershen08/vue-masonry). And because of that, we had to split components and router into server and client versions.
9091

9192
To remove that complexity, we will probably try to use a pure-CSS approach to generate the responsive grid, as described in [this issue on Github](https://github.com/creativecommons/cccatalog-frontend/issues/489). If that doesn't work, we'll use something like [vue-client-only](https://github.com/egoist/vue-client-only).
93+
---
94+
series:

content/blog/series/contents.lr

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_model: blog-series

models/blog-post.ini

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ size = large
1212
label = Categories
1313
type = strings
1414

15+
[fields.series]
16+
label = Select the Series
17+
type = select
18+
source = record.parent.parent.children.get('series').children.all()
19+
1520
[fields.pub_date]
1621
label = Publication date
1722
type = date
@@ -20,7 +25,7 @@ width = 1/2
2025
[fields.author]
2126
label = Author
2227
type = select
23-
// TODO: this is far too opaque, fix this. basically it's finding authors by
28+
// TODO: this is far too opaque, fix this. basically its finding authors by
2429
// going up to entries.blog, then getting everything in
2530
// the blog.authors.<author name> files
2631
source = record.parent.parent.children.get('authors').children.all()

models/blog-series.ini

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[model]
2+
name = Blog Series
3+
label = Blog Series
4+
hidden = yes
5+
protected = yes
6+
7+
[children]
8+
model = single-series
9+
order_by = name

models/single-series.ini

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[model]
2+
name = Single Series
3+
label = {{ this.name }}
4+
hidden = yes
5+
6+
[children]
7+
replaced_with = site.query(this.parent.parent.path + '/entries').filter(F.series.contains(this))
8+
9+
[fields.name]
10+
label = Name
11+
type = string

templates/blog-post.html

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
{% block header %}{{ this.parent.title }}{% endblock %}
99
{% block body %}
1010
<h2 class="mb-0">{{ this.title }}</h2>
11+
{% if this.series|length %}
12+
<div class="card bg-light">
13+
<div class="card-body p-2">
14+
<p class="meta my-0"><span class="mr-2"><strong>This blog is part of the series :</strong></span>
15+
<a href="/blog/series/{{this.series}}/">{{ this.series }}</a>
16+
</p>
17+
</div>
18+
</div>
19+
{% endif %}
20+
1121
{{ check_file('content' + this.parent.parent.path + '/authors/' + this.author + '/contents.lr') }}
1222
<p class="meta text-muted mt-0">by <a href="{{ author|url }}">{{ render_author_name(author) }}</a>
1323
on {{ this.pub_date|dateformat('EEEE, yyyy-''MM-d') }}</p>

templates/blog-series.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "layout.html" %}
2+
{% from "macros/categories.html" import render_categories %}
3+
{% block title %}{{ this.parent.children.get('entries').title }}{% endblock %}
4+
{% block header %}{{ this.parent.children.get('entries').title }}{% endblock %}
5+
{% block body %}
6+
<h2>All Series</h2>
7+
{{ render_categories(this) }}
8+
{% endblock %}

templates/macros/posts.html

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
{% set author = post.parent.parent.children.get('authors').children.get(post.author) %}
77
<li>
88
<a href="{{ post|url }}">{{ post.title }}</a>
9+
{% if post.series|length %}
10+
<p class="meta my-0"><span class="mr-2"><strong>This blog is part of the series :</strong></span>
11+
<a class="badge badge-secondary" href="/blog/series/{{post.series}}/">{{ post.series }}</a>
12+
</p>
13+
{% endif %}
914
<p class="text-muted small">by <a href="{{ author|url }}">{{ render_author_name(author) }}</a>
1015
on {{ post.pub_date|dateformat("YYYY-MM-dd") }}</p>
1116
</li>

templates/single-series.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends "layout.html" %}
2+
3+
{% from "macros/posts.html" import render_posts %}
4+
5+
{% block title %}{{ this.name + ' - ' + this.parent.parent.children.get('entries').title }}{% endblock %}
6+
{% block header %}{{ this.parent.parent.children.get('entries').title }}{% endblock %}
7+
{% block body %}
8+
<h2>All posts under Series "{{ this.name }}"</h2>
9+
{{ render_posts(this.children) }}
10+
<hr>
11+
<strong><a href="{{ this.parent|url }}">All Series</a></strong>
12+
{% endblock %}

0 commit comments

Comments
 (0)