tiptap/docs/gridsome.server.js

98 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-12-08 04:02:22 +08:00
const path = require('path')
2019-12-08 05:23:49 +08:00
const globby = require('globby')
const { createDefaultOpenGraphImage, createSpecificOpenGraphImage } = require('./utilities/opengraph-images')
createDefaultOpenGraphImage('The headless editor framework for web artisans.', 'static/images/og-image.png')
2020-08-18 15:36:26 +08:00
module.exports = function (api) {
2020-08-18 01:08:32 +08:00
2020-10-31 01:11:54 +08:00
api.setClientOptions({
cwd: process.cwd(),
})
2021-02-26 23:35:53 +08:00
let numberOfPages = 0
let numberOfDemos = 0
2021-02-04 16:57:35 +08:00
api.loadSource(() => {
/**
* Generate pages for all demo components for testing purposes
*/
2021-02-07 03:27:28 +08:00
const demos = []
2021-02-03 06:28:17 +08:00
globby.sync('./src/demos/**/index.(vue|jsx)').forEach(file => {
const match = file.match(
2021-02-03 06:28:17 +08:00
new RegExp(/\.\/src\/demos\/([\S]+)\/index.(vue|jsx)/i),
)
if (!match) {
return
}
2021-02-07 03:27:28 +08:00
demos.push(match[1])
})
2021-02-26 23:35:53 +08:00
numberOfDemos = demos.length
2021-02-07 03:27:28 +08:00
api.createPages(({ createPage }) => {
createPage({
path: '/demos',
component: './src/templates/DemoPages/index.vue',
context: {
demos,
},
})
demos.forEach(name => {
createPage({
2021-02-07 03:27:28 +08:00
path: `/demos/${name}`,
component: './src/templates/DemoPage/index.vue',
context: {
2021-02-07 03:27:28 +08:00
name,
},
})
})
})
2020-08-18 15:36:26 +08:00
})
2020-08-18 01:08:32 +08:00
2019-12-08 04:02:22 +08:00
api.chainWebpack(config => {
config.resolve.extensions
.add('.ts')
2021-03-08 20:19:05 +08:00
.add('.tsx')
2020-04-29 05:25:56 +08:00
.add('.jsx')
2019-12-08 07:16:44 +08:00
config.module
.rule('typescript')
2020-09-24 05:38:11 +08:00
.test(/\.tsx?$/)
.use()
.loader('ts-loader')
2020-10-23 17:24:27 +08:00
.options({ transpileOnly: false, appendTsSuffixTo: [/\.vue$/] })
2020-04-17 01:13:21 +08:00
config.module
.rule('jsx')
2020-10-02 03:14:00 +08:00
.test(/\.jsx$/)
2020-09-24 05:38:11 +08:00
.use()
.loader('babel-loader')
2020-04-22 04:11:57 +08:00
globby.sync('../packages/*', { onlyDirectories: true })
.map(name => name.replace('../packages/', ''))
2019-12-08 05:23:49 +08:00
.forEach(name => {
config.resolve.alias
2020-11-10 23:29:31 +08:00
.set(`@tiptap/${name}`, path.resolve(`../packages/${name}/src/index.ts`))
2019-12-08 05:23:49 +08:00
})
2019-12-08 04:02:22 +08:00
})
api.onCreateNode(options => {
2021-02-26 23:35:53 +08:00
if (options.internal.typeName === 'DocPage') {
numberOfPages += 1
if (process.env.NODE_ENV === 'production') {
createSpecificOpenGraphImage(options.title, options.content, `static/images${options.path}og-image.png`)
}
2021-02-03 23:38:23 +08:00
}
})
2021-02-26 23:35:53 +08:00
api.configureServer(() => {
console.log(`[STATS] ${numberOfPages} pages, ${numberOfDemos} interactive demos`)
})
2019-12-08 04:02:22 +08:00
}