Skip to content

Commit 8fff97d

Browse files
committed
[CM2] Create theme/common/partials2
It contains new page partials like collection and facet. So, if compilerVersion is 2: - theme settings is overridden as zen - partials2 is copied and registered Also, introduce a serialize function in facet and collection. - Previously facet model was using a 'presentationFacets' for making templates' job easy. Now that logic is moved to a serialize function and it is exported as a model method. - Collection's serialize just maps its facets to their serialized versions - Although feels wrong, homepage model now requires collection model to be able to serialize it for the homepage template to access collections' facets in the same way as collection page does. All this definitely inspires a serialization step of contentModel before rendering.
1 parent 7361e1d commit 8fff97d

File tree

33 files changed

+499
-26
lines changed

33 files changed

+499
-26
lines changed

src/compiler/contentModel2/models/collection/facet.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,38 @@ function linkEntryFieldsToFacets(entry, facets) {
116116
})
117117
}
118118

119+
function serialize(facet) {
120+
return {
121+
...facet,
122+
title: facet.key,
123+
get keys() {
124+
return Array.from(facet.map.keys())
125+
},
126+
get entries() {
127+
return Array.from(facet.map, ([key, value]) => {
128+
let linkedFacet
129+
try {
130+
linkedFacet = JSON.parse(key)
131+
} catch { }
132+
const slug = linkedFacet ? linkedFacet.slug : makeSlug(key)
133+
return {
134+
key: linkedFacet ? linkedFacet.title : key,
135+
value,
136+
slug
137+
}
138+
})
139+
}
140+
}
141+
}
142+
119143
function Facet() {
120144
const addressSegment = 'by' // alt: browse, filter, view
121145

122146
return {
123147
collectFacets,
124148

149+
serialize,
150+
125151
linkEntryFieldsToFacets,
126152

127153
create: (key, map, context) => {
@@ -141,27 +167,7 @@ function Facet() {
141167
afterEffects: (contentModel, facet) => {},
142168

143169
render: (renderer, facets, { contentModel, settings, debug }) => {
144-
const presentationFacets = facets.map(f => ({
145-
...f,
146-
title: f.key,
147-
get keys() {
148-
return Array.from(f.map.keys())
149-
},
150-
get entries() {
151-
return Array.from(f.map, ([key, value]) => {
152-
let linkedFacet
153-
try {
154-
linkedFacet = JSON.parse(key)
155-
} catch { }
156-
const slug = linkedFacet ? linkedFacet.slug : makeSlug(key)
157-
return {
158-
key: linkedFacet ? linkedFacet.title : key,
159-
value,
160-
slug
161-
}
162-
})
163-
}
164-
}))
170+
const presentationFacets = facets.map(serialize)
165171

166172
// /by
167173
const renderAllFacetsPage = () => {

src/compiler/contentModel2/models/collection/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ function locatePinnedEntries(entries) {
4646
}
4747
}
4848

49+
function serialize(collection) {
50+
return {
51+
...collection,
52+
facets: collection.facets.map(models.facet().serialize)
53+
}
54+
}
55+
4956
const defaultSettings = {
5057
defaultCategoryName: '',
5158
collectionAliases: [],
@@ -72,6 +79,8 @@ module.exports = function Collection(settings = defaultSettings, contentTypes =
7279
}
7380

7481
return {
82+
serialize,
83+
7584
match: node => {
7685
const hasCollectionIndex = node.children?.find(isCollectionIndexFile)
7786
const hasCollectionData = node.children?.find(childNode => isDataFile(childNode, node))
@@ -289,7 +298,7 @@ module.exports = function Collection(settings = defaultSettings, contentTypes =
289298
content: collection.content,
290299
data: {
291300
...contentModel,
292-
collection,
301+
collection: serialize(collection),
293302
pagination: paginationData,
294303
posts: pageOfPosts,
295304
settings,

src/compiler/contentModel2/models/homepage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const { join, resolve } = require('path')
22
const { isTemplateFile } = require('../helpers')
33
const models = {
44
_baseEntry: require('./_baseEntry'),
5-
attachment: require('./attachment')
5+
attachment: require('./attachment'),
6+
collection: require('./collection')
67
}
78

89
const defaultSettings = {
@@ -72,6 +73,7 @@ module.exports = function Homepage(settings = defaultSettings) {
7273
content: homepage.content,
7374
data: {
7475
...contentModel,
76+
collections: contentModel.collections.map(models.collection().serialize),
7577
homepage,
7678
settings,
7779
debug

src/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module.exports = {
7070
}
7171
_settings = _.omit({
7272
...userSettings,
73+
theme: userSettings.compilerVersion === 1 ? _settings.theme : 'zen',
7374
site: {
7475
title: userSettings.title,
7576
description: userSettings.description,

src/theme/common/partials2/base/base-includes.hbs

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script type="module" src="{{assetsPath}}/common/dictionary.js"></script>

src/theme/common/partials2/base/base-style.hbs

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#if (hasCustomScript)}}
2+
<script type="text/javascript" src="{{assetsPath}}/custom/script.js"></script>
3+
{{/if}}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{#if (hasCustomStyle)}}
2+
<link rel="stylesheet" href="{{assetsPath}}/custom/style.css">
3+
{{/if}}
4+
5+
{{#if (hasThemeSettings)}}
6+
<link rel="stylesheet" href="{{assetsPath}}/custom/theme-settings.css">
7+
{{/if}}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{#if (isEnabled "rss")}}
2+
{{#if (isCategoryPage) }}
3+
<link rel="alternate" type="application/rss+xml" title="{{settings.site.title}} {{category.name}} Feed" href="{{settings.site.url}}{{ category.permalink }}/feed.xml">
4+
{{else}}
5+
<link rel="alternate" type="application/rss+xml" title="{{settings.site.title}} Feed" href="{{settings.site.url}}/feed.xml">
6+
{{/if}}
7+
{{/if}}
8+
9+
{{#if (isEnabled "syntaxHighlighting")}}
10+
<link rel="stylesheet" href="{{assetsPath}}/features/highlight/styles/default.min.css">
11+
<script src="{{assetsPath}}/features/highlight/highlight.min.js"></script>
12+
<script>hljs.highlightAll();</script>
13+
{{/if}}
14+
15+
{{#if (isEnabled "search")}}
16+
<link rel="stylesheet" href="{{assetsPath}}/features/search/search.css">
17+
<script defer type="module" src="{{assetsPath}}/features/search/search.js"></script>
18+
{{/if}}

0 commit comments

Comments
 (0)