Skip to content

Commit 1193d54

Browse files
committed
Add getContentTypes button to explorePanel
Export contentTypes from compiler as part of return
1 parent 5d37a6e commit 1193d54

10 files changed

Lines changed: 64 additions & 7 deletions

File tree

src/cms/api/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const createAPI = (providers) => {
33
api.settings = require('./models/settings')(providers, api)
44
api.fileSystemTree = require('./models/fileSystemTree')(providers, api)
55
api.contentModel = require('./models/contentModel')(providers, api)
6+
api.contentTypes = require('./models/contentTypes')(providers, api)
67
api.collections = require('./models/collections')(providers, api)
78
api.categories = require('./models/categories')(providers, api)
89
api.category = require('./models/category')(providers, api)

src/cms/api/models/contentTypes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const createContentTypesModel = ({ getContentTypes }) => {
2+
return {
3+
get: getContentTypes
4+
}
5+
}
6+
7+
module.exports = createContentTypesModel

src/cms/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const createCMS = (initialState = {}) => {
88
settings: {},
99
fileSystemTree: [],
1010
contentModel: {},
11+
contentTypes: [],
1112
watcher: {
1213
directory: undefined,
1314
isRunning: false,
@@ -19,6 +20,7 @@ const createCMS = (initialState = {}) => {
1920
getSettings: () => state.settings,
2021
getFileSystemTree: () => state.fileSystemTree,
2122
getContentModel: () => state.contentModel,
23+
getContentTypes: () => state.contentTypes,
2224
getSSGOptions: () => state.ssgOptions,
2325
isWatching: (directory) => {
2426
if (directory) {

src/cms/server/public/api.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ const api = {
146146
}
147147
},
148148

149+
contentTypes: {
150+
get: async () => {
151+
const response = await fetch('/api/contentTypes', {
152+
method: 'get',
153+
headers: {
154+
'content-type': 'application/json'
155+
}
156+
})
157+
return response.json()
158+
}
159+
},
160+
149161
fileSystemTree: {
150162
get: async () => {
151163
const response = await fetch('/api/fileSystemTree', {

src/cms/server/public/app/explorePanel.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import ssgStopWatcher from './explorePanel/ssgStopWatcher.js'
55
import getSSGOptions from './explorePanel/getSSGOptions.js'
66
import getSettings from './explorePanel/getSettings.js'
77
import updateSettings from './explorePanel/updateSettings.js'
8-
import getFileSystemTree from './explorePanel/getFileSystemTree.js'
8+
import getContentTypes from './explorePanel/getContentTypes.js'
99
import getContentModel from './explorePanel/getContentModel.js'
10+
import getFileSystemTree from './explorePanel/getFileSystemTree.js'
1011
import getCollections from './explorePanel/getCollections.js'
1112
import getSubpages from './explorePanel/getSubpages.js'
1213
import getSubpage from './explorePanel/getSubpage.js'
@@ -27,12 +28,15 @@ const template = () => {
2728
<button type="button" id="get-settings-btn">get settings</button>
2829
<button type="button" id="update-settings-btn">update settings</button>
2930
30-
<p>fileSystemTree</p>
31-
<button type="button" id="get-file-system-tree-btn">get fileSystemTree</button>
31+
<p>contentTypes</p>
32+
<button type="button" id="get-content-types-btn">get contentTypes</button>
3233
3334
<p>contentModel</p>
3435
<button type="button" id="get-content-model-btn">get contentModel</button>
3536
37+
<p>fileSystemTree</p>
38+
<button type="button" id="get-file-system-tree-btn">get fileSystemTree</button>
39+
3640
<p>collections</p>
3741
<button type="button" id="get-collections-btn">get all collections</button>
3842
@@ -64,8 +68,9 @@ const makeButtonsWork = (panel) => {
6468
panel.querySelector('#get-ssg-options-btn').addEventListener('click', getSSGOptions)
6569
panel.querySelector('#get-settings-btn').addEventListener('click', getSettings)
6670
panel.querySelector('#update-settings-btn').addEventListener('click', updateSettings)
67-
panel.querySelector('#get-file-system-tree-btn').addEventListener('click', getFileSystemTree)
71+
panel.querySelector('#get-content-types-btn').addEventListener('click', getContentTypes)
6872
panel.querySelector('#get-content-model-btn').addEventListener('click', getContentModel)
73+
panel.querySelector('#get-file-system-tree-btn').addEventListener('click', getFileSystemTree)
6974
panel.querySelector('#get-collections-btn').addEventListener('click', getCollections)
7075
panel.querySelector('#get-subpages-btn').addEventListener('click', getSubpages)
7176
panel.querySelector('#get-subpage-btn').addEventListener('click', getSubpage)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import api from '../../api.js'
2+
import dialog from '../components/dialog.js'
3+
4+
export default async () => {
5+
dialog.textContent('Loading').show()
6+
7+
const contentTypes = await api.contentTypes.get()
8+
9+
dialog.textContent(JSON.stringify(contentTypes, null, 2))
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const express = require('express')
2+
3+
module.exports = express.Router()
4+
.get('/', async (req, res, next) => {
5+
try {
6+
res.status(200).json(
7+
await req.api.contentTypes.get()
8+
)
9+
} catch (e) {
10+
console.log('Error getting contentTypes', e)
11+
return res.status(500).send(e)
12+
}
13+
})

src/cms/server/router/api/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = express.Router()
44
.use('/settings', require('./settings'))
55
.use('/fileSystemTree', require('./fileSystemTree'))
66
.use('/contentModel', require('./contentModel'))
7+
.use('/contentTypes', require('./contentTypes'))
78
.use('/collections', require('./collections'))
89
.use('/categories', require('./categories'))
910
.use('/category', require('./category'))

src/ssg/compiler/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ module.exports = class Compiler {
4646

4747
return {
4848
fileSystemTree,
49-
contentModel
49+
contentModel,
50+
contentTypes
5051
}
5152
}
5253
}

src/ssg/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ const build = async ({ mode = 'build', rootDirectory, refreshTheme, debug, cli }
3737
await SiteDirectory.create()
3838
await CNAME.create()
3939

40-
const { fileSystemTree, contentModel } = await new Compiler({
40+
const {
41+
fileSystemTree,
42+
contentModel,
43+
contentTypes
44+
} = await new Compiler({
4145
FileSystemParser,
4246
ContentModel,
4347
Renderer,
@@ -76,7 +80,8 @@ const build = async ({ mode = 'build', rootDirectory, refreshTheme, debug, cli }
7680
return {
7781
settings,
7882
fileSystemTree,
79-
contentModel
83+
contentModel,
84+
contentTypes
8085
}
8186
}
8287

0 commit comments

Comments
 (0)