Skip to content

Commit a7739bb

Browse files
committed
Expose whole contentModel to every render target
- Expose relevant model as a separate data field instead of spreading into it - Make sure post templates don't break because of it. Spread the model object just for post/content inside the template. So templates can refer to post as ctx - Side effect: post.tags shadows contentModel.tags - but only inside post.content template, probably not a big miss and curable if needed - Remove unnecessary categoryPosts field from category template data
1 parent 2d4a83b commit a7739bb

File tree

9 files changed

+20
-30
lines changed

9 files changed

+20
-30
lines changed

packages/theme-default/partials/pages/post/photo/index.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</header>
66

77
<main {{region "main"}}>
8-
{{>pages/post/photo/content}}
8+
{{>pages/post/photo/content ...post}}
99
</main>
1010
{{/layouts/single-column}}
1111
{{/base}}

src/compiler/rendering/views/category-page.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ const { join } = require('path')
22
const Settings = require('../../../settings')
33
const Debug = require('../../../debug')
44

5-
const renderCategoryPages = (Renderer, { homepage, categories, posts, subpages }) => {
5+
const renderCategoryPages = (Renderer, contentModel) => {
66
const settings = Settings.getSettings()
7-
const compilation = categories.map(category => {
7+
const compilation = contentModel.categories.map(category => {
88
return Renderer.render({
99
template: `pages/category/${category.type}`,
1010
outputPath: join(settings.out, category.slug, 'index.html'),
1111
content: category.content,
1212
data: {
13-
homepage,
13+
...contentModel,
1414
category,
15-
categories,
16-
subpages,
17-
posts,
18-
categoryPosts: category.posts,
1915
settings,
2016
debug: Debug.getDebug()
2117
}

src/compiler/rendering/views/homepage.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ const Debug = require('../../../debug')
33
const { paginate } = require('../helpers/pagination')
44
const { filterPosts } = require('../helpers/filterPosts')
55

6-
const renderHomepage = async (Renderer, { homepage, categories, posts, subpages }) => {
6+
const renderHomepage = async (Renderer, contentModel) => {
77
const settings = Settings.getSettings()
8+
const { homepage, posts } = contentModel
89
return paginate({
910
page: homepage,
1011
posts: filterPosts(homepage, posts),
@@ -16,11 +17,10 @@ const renderHomepage = async (Renderer, { homepage, categories, posts, subpages
1617
outputPath,
1718
content: homepage.content,
1819
data: {
19-
...homepage,
20+
...contentModel,
21+
homepage,
2022
pagination: paginationData,
2123
posts: pageOfPosts,
22-
categories,
23-
subpages,
2424
settings,
2525
debug: Debug.getDebug()
2626
}

src/compiler/rendering/views/posts.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const { join } = require('path')
22
const Settings = require('../../../settings')
33
const Debug = require('../../../debug')
44

5-
const renderPosts = (Renderer, { homepage, categories, posts, subpages }) => {
5+
const renderPosts = (Renderer, contentModel) => {
66
const settings = Settings.getSettings()
7-
const compilation = posts.map(post => {
7+
const compilation = contentModel.posts.map(post => {
88
const outputPath = join(
99
settings.out,
1010
post.permalink,
@@ -15,11 +15,8 @@ const renderPosts = (Renderer, { homepage, categories, posts, subpages }) => {
1515
outputPath,
1616
content: post.content,
1717
data: {
18-
...post,
19-
homepage,
20-
posts,
21-
categories,
22-
subpages,
18+
...contentModel,
19+
post,
2320
settings,
2421
debug: Debug.getDebug()
2522
}

src/compiler/rendering/views/subpages.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const { join } = require('path')
22
const Settings = require('../../../settings')
33
const Debug = require('../../../debug')
44

5-
const renderSubpages = (Renderer, { homepage, categories, posts, subpages }) => {
5+
const renderSubpages = (Renderer, contentModel) => {
66
const settings = Settings.getSettings()
7-
const compilation = subpages.map(subpage => {
7+
const compilation = contentModel.subpages.map(subpage => {
88
const outputPath = join(
99
settings.out,
1010
subpage.permalink,
@@ -15,11 +15,8 @@ const renderSubpages = (Renderer, { homepage, categories, posts, subpages }) =>
1515
outputPath,
1616
content: subpage.content,
1717
data: {
18-
...subpage,
19-
homepage,
20-
posts,
21-
categories,
22-
subpages,
18+
...contentModel,
19+
subpage,
2320
settings,
2421
debug: Debug.getDebug()
2522
}

src/theme/common/partials/pages/category/basic.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<main {{region "main"}}>
88
{{> @partial-block }}
9-
{{>components/posts posts=categoryPosts}}
9+
{{>components/posts posts=category.posts}}
1010
</main>
1111
{{/layouts/single-column}}
1212
{{/base}}

src/theme/common/partials/pages/post/audio/index.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</header>
66

77
<main {{region "main"}}>
8-
{{>pages/post/audio/content}}
8+
{{>pages/post/audio/content ...post}}
99
</main>
1010
{{/layouts/single-column}}
1111
{{/base}}

src/theme/common/partials/pages/post/text/index.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</header>
66

77
<main {{region "main"}}>
8-
{{>pages/post/text/content}}
8+
{{>pages/post/text/content ...post}}
99
</main>
1010
{{/layouts/single-column}}
1111
{{/base}}

src/theme/common/template-helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545

4646
pageTitle() {
4747
if (this.page === 'post' || this.page === 'subpage') {
48-
return `${this.title} / ${this.settings.site.title}`
48+
return `${this.post.title} / ${this.settings.site.title}`
4949
}
5050
if (this.page === 'category') {
5151
return `${this.category.name} / ${this.settings.site.title}`

0 commit comments

Comments
 (0)