Skip to content

Commit df0dd10

Browse files
committed
[CM2] WIP continues for rendering2
- Add absolutePath field into fileSystemTree to vastly simplify copying assets - Add a copy method to renderer for copying assets/files - Implement copyAssets view - Delete the legacy localAsset (attachment) view. Copy them as part of their parent entry's view - Remove pagination from homepage. Pagination takes places in collections. Collection indexes may be used as homepage (in the future) - Implement post view as part of collection - Implement tags and category views as part of collection. And paginate them - Assume a postsPerPage field in categories and collections. Cascade: settings.ppp > collection.ppp > category.ppp - Render categories, tags and posts as part of collection view - Add date field to asset just like in attachment - Fix attachment outputPath (it was assuming it's always in a category) - Homepage passes a 'homepage' (instead of 'page') context to its attachments, so it doesn't count in attachment outputPath - Delete filterPosts helper. Filtering posts sounds like a template's job - Init settings in CM2 test so there's some settings.out to work with - Call move getSettings() call into function runtimes, so settings.out is not undefined when testing contentModel2 - Update CM2 test fixtures to include absolutePath in FS nodes
1 parent b3b175a commit df0dd10

File tree

24 files changed

+293
-201
lines changed

24 files changed

+293
-201
lines changed

src/compiler/contentModel2/models/asset.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const { join } = require('path')
2-
const settings = require('../../../settings').getSettings()
2+
const Settings = require('../../../settings')
33

44
function asset(node) {
5+
const settings = Settings.getSettings()
6+
57
const permalink = (
68
settings.permalinkPrefix +
79
[settings.assetsDirectory, node.name].join('/')
@@ -16,7 +18,8 @@ function asset(node) {
1618
return {
1719
...node,
1820
permalink,
19-
outputPath
21+
outputPath,
22+
date: new Date(node.stats.birthtime || Date.now())
2023
}
2124
}
2225

src/compiler/contentModel2/models/attachment.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const { join } = require('path')
2-
const settings = require('../../../settings').getSettings()
2+
const Settings = require('../../../settings')
33

44
function attachment(node, context) {
5+
const settings = Settings.getSettings()
6+
57
const permalink = (
68
settings.permalinkPrefix +
79
[
@@ -16,7 +18,7 @@ function attachment(node, context) {
1618
const outputPath = join(...[
1719
settings.out,
1820
context.collection?.slug,
19-
context.category?.isDefaultCategory ? '' : context.category.slug,
21+
context.category?.isDefaultCategory ? '' : context.category?.slug,
2022
context.post?.slug,
2123
context.page?.slug,
2224
node.name

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
const { join } = require('path')
22
const frontMatter = require('front-matter')
33
const makeSlug = require('slug')
4-
const settings = require('../../../../settings').getSettings()
4+
const Settings = require('../../../../settings')
55
const { isTemplateFile } = require('../../helpers')
66
const models = {
77
post: require('./post'),
88
attachment: require('../attachment')
99
}
1010

1111
function category(node, context) {
12+
const settings = Settings.getSettings()
13+
1214
if (node.isDefaultCategory) {
1315
const slug = makeSlug(settings.defaultCategoryName)
1416
const permalink = (

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { join } = require('path')
22
const _ = require('lodash')
33
const frontMatter = require('front-matter')
44
const makeSlug = require('slug')
5-
const settings = require('../../../../settings').getSettings()
5+
const Settings = require('../../../../settings')
66
const { isTemplateFile } = require('../../helpers')
77
const models = {
88
attachment: require('../attachment'),
@@ -11,6 +11,8 @@ const models = {
1111
}
1212

1313
function collection(node) {
14+
const settings = Settings.getSettings()
15+
1416
function collectPostTags(post) {
1517
post.tags.forEach(postTag => {
1618
let collectionTag = tree.tags.find(t => t.name === postTag.name)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
const { join } = require('path')
2-
const settings = require('../../../../settings').getSettings()
2+
const Settings = require('../../../../settings')
33
const { parseTags } = require('../../helpers')
44
const models = {
55
_baseEntry: require('../_baseEntry'),
66
tag: require('./tag')
77
}
88

99
function post(node, context) {
10+
const settings = Settings.getSettings()
11+
1012
const baseEntryProps = models._baseEntry(node, ['index', 'post'])
1113

1214
const permalink = (

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const { join } = require('path')
22
const makeSlug = require('slug')
3-
const settings = require('../../../../settings').getSettings()
3+
const Settings = require('../../../../settings')
44

55
function tag(name, context) {
6+
const settings = Settings.getSettings()
67
const slug = makeSlug(name)
78
const permalink = (
89
settings.permalinkPrefix +

src/compiler/contentModel2/models/homepage.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const { join } = require('path')
2-
const settings = require('../../../settings').getSettings()
2+
const Settings = require('../../../settings')
33
const models = {
44
_baseEntry: require('./_baseEntry')
55
}
66

77
function homepage(node) {
8+
const settings = Settings.getSettings()
9+
810
const baseEntryProps = models._baseEntry(node, ['index'])
911

1012
const permalink = settings.permalinkPrefix
@@ -20,7 +22,7 @@ function homepage(node) {
2022
return {
2123
...baseEntryProps,
2224
attachments: baseEntryProps.attachments.map(a => a({
23-
page: pageContext
25+
homepage: pageContext
2426
})),
2527
permalink,
2628
outputPath

src/compiler/contentModel2/models/subpage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const { join } = require('path')
2-
const settings = require('../../../settings').getSettings()
2+
const Settings = require('../../../settings')
33
const models = {
44
_baseEntry: require('./_baseEntry')
55
}
66

77
function subpage(node) {
8+
const settings = Settings.getSettings()
9+
810
const baseEntryProps = models._baseEntry(node, ['index', 'page'])
911

1012
const permalink = (

src/compiler/fileSystem.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const _explore = async (currentPath, depth = 0) => {
4747
const baseProperties = {
4848
name: fileName,
4949
path: relative(rootPath, accumulatedPath),
50+
absolutePath: accumulatedPath,
5051
stats: { birthtime },
5152
depth,
5253
}

src/compiler/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const compile2 = async () => {
1010

1111
const fileSystemTree = await FileSystem.exploreTree()
1212
const contentModel = ContentModel2.create(fileSystemTree)
13+
14+
return {}
15+
1316
await Rendering2.render(contentModel)
1417
Debug.timeEnd('compiler')
1518
return {

0 commit comments

Comments
 (0)