From de3c19219d2f3f203e6bfbb31572756af21a5ed7 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Tue, 15 Feb 2022 21:32:51 -0500 Subject: [PATCH 1/8] initial WIP --- packages/cli/src/lifecycles/config.js | 15 +--- packages/cli/src/lifecycles/graph.js | 6 +- .../plugins/resource/plugin-standard-html.js | 68 ++++------------- packages/cli/src/templates/app.html | 3 +- .../build.config.error-title.spec.js | 49 ------------ .../greenwood.config.js | 3 - .../build.config.meta.spec.js | 76 +++++++------------ .../build.config.meta/greenwood.config.js | 10 --- .../build.config.meta/src/templates/page.html | 14 ++++ .../build.config.title.spec.js | 13 ++-- .../build.config.title/greenwood.config.js | 3 - .../src/templates/page.html | 5 ++ .../build.default.markdown.spec.js | 11 +-- .../greenwood.config.js | 3 - .../build.default.spa.spec.js | 7 +- .../build.default.ssr.spec.js | 4 +- .../build.default.ssr/src/pages/artists.js | 57 +++++--------- .../build.default.ssr/src/templates/app.html | 3 +- .../src/templates/app.html | 1 + .../src/templates/app.html | 2 +- .../fixtures/layouts/app.html | 1 + .../fixtures/layouts/app.html | 1 + .../cases/develop.ssr/develop.ssr.spec.js | 4 +- .../cases/develop.ssr/src/pages/artists.js | 55 +++++--------- .../cases/develop.ssr/src/templates/app.html | 1 - .../init/src/template/greenwood.config.js | 3 - .../cases/init.default/init.default.spec.js | 18 +---- packages/plugin-graphql/src/schema/config.js | 11 --- .../cases/query-config/greenwood.config.js | 1 - .../cases/query-config/query-config.spec.js | 7 +- .../query-config/src/components/footer.js | 2 +- .../cases/build.default/build.default.spec.js | 2 +- .../cases/build.default/src/pages/artists.js | 6 +- .../build.default/src/templates/app.html | 2 +- test/smoke-test.js | 2 +- 35 files changed, 133 insertions(+), 336 deletions(-) delete mode 100644 packages/cli/test/cases/build.config.error-title/build.config.error-title.spec.js delete mode 100644 packages/cli/test/cases/build.config.error-title/greenwood.config.js delete mode 100644 packages/cli/test/cases/build.config.meta/greenwood.config.js create mode 100644 packages/cli/test/cases/build.config.meta/src/templates/page.html delete mode 100644 packages/cli/test/cases/build.config.title/greenwood.config.js create mode 100644 packages/cli/test/cases/build.config.title/src/templates/page.html delete mode 100644 packages/cli/test/cases/build.default.markdown/greenwood.config.js delete mode 100644 packages/init/src/template/greenwood.config.js diff --git a/packages/cli/src/lifecycles/config.js b/packages/cli/src/lifecycles/config.js index 36b357b7e..8914f153e 100644 --- a/packages/cli/src/lifecycles/config.js +++ b/packages/cli/src/lifecycles/config.js @@ -42,8 +42,6 @@ const defaultConfig = { port: 8080, optimization: optimizations[0], interpolateFrontmatter: false, - title: 'My App', - meta: [], plugins: greenwoodPlugins, markdown: { plugins: [], settings: {} }, prerender: true, @@ -60,7 +58,7 @@ const readAndMergeConfig = async() => { if (fs.existsSync(path.join(process.cwd(), 'greenwood.config.js'))) { const userCfgFile = (await import(pathToFileURL(path.join(process.cwd(), 'greenwood.config.js')))).default; - const { workspace, devServer, title, markdown, meta, optimization, plugins, port, prerender, staticRouter, pagesDirectory, templatesDirectory, interpolateFrontmatter } = userCfgFile; + const { workspace, devServer, markdown, optimization, plugins, port, prerender, staticRouter, pagesDirectory, templatesDirectory, interpolateFrontmatter } = userCfgFile; // workspace validation if (workspace) { @@ -87,17 +85,6 @@ const readAndMergeConfig = async() => { } } - if (title) { - if (typeof title !== 'string') { - reject('Error: greenwood.config.js title must be a string'); - } - customConfig.title = title; - } - - if (meta && meta.length > 0) { - customConfig.meta = meta; - } - if (typeof optimization === 'string' && optimizations.indexOf(optimization.toLowerCase()) >= 0) { customConfig.optimization = optimization; } else if (optimization) { diff --git a/packages/cli/src/lifecycles/graph.js b/packages/cli/src/lifecycles/graph.js index de46062e7..0594b637e 100644 --- a/packages/cli/src/lifecycles/graph.js +++ b/packages/cli/src/lifecycles/graph.js @@ -39,7 +39,7 @@ const generateGraph = async (compilation) => { .replace(extension, '') .replace(/\\/g, '/'); let template = 'page'; - let title = ''; + let title = null; let imports = []; let label = ''; let id; @@ -51,7 +51,7 @@ const generateGraph = async (compilation) => { const { attributes } = fm(fileContents); template = attributes.template || 'page'; - title = attributes.title || compilation.config.title || ''; + title = attributes.title || title; id = attributes.label || filename.split(path.sep)[filename.split(path.sep).length - 1].replace(extension, ''); imports = attributes.imports || []; label = id.split('-') @@ -133,7 +133,6 @@ const generateGraph = async (compilation) => { .replace(extension, '') .replace(/\\/g, '/') .concat('/'); - title = `${compilation.config.title} - ${label}`; let ssrFrontmatter; filePath = route; @@ -243,7 +242,6 @@ const generateGraph = async (compilation) => { filename: '404.html', route: '/404/', path: '404.html', - title: 'Not Found', id: '404', label: 'Not Found' } diff --git a/packages/cli/src/plugins/resource/plugin-standard-html.js b/packages/cli/src/plugins/resource/plugin-standard-html.js index 7a6eef433..75f88ee56 100644 --- a/packages/cli/src/plugins/resource/plugin-standard-html.js +++ b/packages/cli/src/plugins/resource/plugin-standard-html.js @@ -58,7 +58,7 @@ const getPageTemplate = (fullPath, templatesDir, template, contextPlugins = [], return contents; }; -const getAppTemplate = (contents, templatesDir, customImports = [], contextPlugins, enableHud) => { +const getAppTemplate = (contents, templatesDir, customImports = [], contextPlugins, enableHud, frontmatterTitle) => { const userAppTemplatePath = `${templatesDir}app.html`; const customAppTemplates = getCustomPageTemplates(contextPlugins, 'app'); @@ -105,11 +105,15 @@ const getAppTemplate = (contents, templatesDir, customImports = [], contextPlugi const headStyles = root.querySelectorAll('head style'); const headTitle = root.querySelector('head title'); const appTemplateHeadContents = appRoot.querySelector('head').innerHTML; - + const title = frontmatterTitle || (headTitle ? headTitle.rawText : null); appTemplateContents = appTemplateContents.replace(/<\/page-outlet>/, body); - if (headTitle) { - appTemplateContents = appTemplateContents.replace(/(.*)<\/title>/, `<title>${headTitle.rawText}`); + if (title) { + if (!appRoot.querySelector('head title')) { + appTemplateContents = appTemplateContents.replace('', '\n '); + } + + appTemplateContents = appTemplateContents.replace(/(.*)<\/title>/, `<title>${title}`); } // merge - diff --git a/packages/cli/test/cases/build.default.workspace-template-app/src/templates/app.html b/packages/cli/test/cases/build.default.workspace-template-app/src/templates/app.html index 6d3315077..f4ae70595 100644 --- a/packages/cli/test/cases/build.default.workspace-template-app/src/templates/app.html +++ b/packages/cli/test/cases/build.default.workspace-template-app/src/templates/app.html @@ -2,6 +2,7 @@ + My App diff --git a/packages/cli/test/cases/build.default.workspace-templates-relative-paths/src/templates/app.html b/packages/cli/test/cases/build.default.workspace-templates-relative-paths/src/templates/app.html index be96376bb..d9408518a 100644 --- a/packages/cli/test/cases/build.default.workspace-templates-relative-paths/src/templates/app.html +++ b/packages/cli/test/cases/build.default.workspace-templates-relative-paths/src/templates/app.html @@ -1,7 +1,7 @@ - + My App diff --git a/packages/cli/test/cases/build.plugins.context/fixtures/layouts/app.html b/packages/cli/test/cases/build.plugins.context/fixtures/layouts/app.html index 77e6480e8..69828b3cb 100644 --- a/packages/cli/test/cases/build.plugins.context/fixtures/layouts/app.html +++ b/packages/cli/test/cases/build.plugins.context/fixtures/layouts/app.html @@ -2,6 +2,7 @@ + My Theme Pack diff --git a/packages/cli/test/cases/develop.plugins.context/fixtures/layouts/app.html b/packages/cli/test/cases/develop.plugins.context/fixtures/layouts/app.html index 77e6480e8..e1170c3c9 100644 --- a/packages/cli/test/cases/develop.plugins.context/fixtures/layouts/app.html +++ b/packages/cli/test/cases/develop.plugins.context/fixtures/layouts/app.html @@ -2,6 +2,7 @@ + My App diff --git a/packages/cli/test/cases/develop.ssr/develop.ssr.spec.js b/packages/cli/test/cases/develop.ssr/develop.ssr.spec.js index 538a063ac..4dbfddc19 100644 --- a/packages/cli/test/cases/develop.ssr/develop.ssr.spec.js +++ b/packages/cli/test/cases/develop.ssr/develop.ssr.spec.js @@ -202,7 +202,7 @@ describe('Develop Greenwood With: ', function() { const title = dom.window.document.querySelectorAll('head > title'); expect(title.length).to.equal(1); - expect(title[0].textContent).to.equal('My App - /artists/'); + expect(title[0].textContent).to.equal('/artists/'); }); it('should have custom metadata in the ', function() { @@ -210,7 +210,7 @@ describe('Develop Greenwood With: ', function() { .filter((tag) => tag.getAttribute('name') === 'description'); expect(metaDescription.length).to.equal(1); - expect(metaDescription[0].getAttribute('content')).to.equal('My App - /artists/ (this was generated server side!!!)'); + expect(metaDescription[0].getAttribute('content')).to.equal('/artists/ (this was generated server side!!!)'); }); it('should be a part of graph.json', function() { diff --git a/packages/cli/test/cases/develop.ssr/src/pages/artists.js b/packages/cli/test/cases/develop.ssr/src/pages/artists.js index cb31b181d..cd1884f91 100644 --- a/packages/cli/test/cases/develop.ssr/src/pages/artists.js +++ b/packages/cli/test/cases/develop.ssr/src/pages/artists.js @@ -4,7 +4,7 @@ async function getTemplate(compilation, route) { return ` - + diff --git a/packages/init/src/template/greenwood.config.js b/packages/init/src/template/greenwood.config.js deleted file mode 100644 index 6152def9a..000000000 --- a/packages/init/src/template/greenwood.config.js +++ /dev/null @@ -1,3 +0,0 @@ -export default { - title: 'My Project' -}; \ No newline at end of file diff --git a/packages/init/test/cases/init.default/init.default.spec.js b/packages/init/test/cases/init.default/init.default.spec.js index fd69e4b91..20f86857f 100644 --- a/packages/init/test/cases/init.default/init.default.spec.js +++ b/packages/init/test/cases/init.default/init.default.spec.js @@ -15,7 +15,7 @@ import chai from 'chai'; import fs from 'fs'; import path from 'path'; import { Runner } from 'gallinago'; -import { fileURLToPath, pathToFileURL, URL } from 'url'; +import { fileURLToPath, URL } from 'url'; const expect = chai.expect; @@ -45,10 +45,6 @@ describe('Scaffold Greenwood With Default Template: ', function() { expect(fs.existsSync(path.join(outputPath, 'src', 'pages'))).to.be.true; }); - it('should generate a greenwood.config.js file', function() { - expect(fs.existsSync(path.join(outputPath, 'greenwood.config.js'))).to.be.true; - }); - it('should generate a .gitignore file', function() { expect(fs.existsSync(path.join(outputPath, '.gitignore'))).to.be.true; }); @@ -92,18 +88,6 @@ describe('Scaffold Greenwood With Default Template: ', function() { }); }); - describe('initial greenwood.config.js contents', function() { - let greenwoodConfig; - - before(async function() { - greenwoodConfig = (await import(pathToFileURL(path.join(outputPath, './greenwood.config.js')))).default; - }); - - it('should have the correct title configuration', function() { - expect(greenwoodConfig.title).to.equal('My Project'); - }); - }); - describe('initial page contents', function() { it('should have the correct contents for src/pages.index.md', function() { const pageContents = fs.readFileSync(path.join(outputPath, 'src/pages/index.md'), 'utf-8'); diff --git a/packages/plugin-graphql/src/schema/config.js b/packages/plugin-graphql/src/schema/config.js index 5f28f7a67..d7400fdc1 100644 --- a/packages/plugin-graphql/src/schema/config.js +++ b/packages/plugin-graphql/src/schema/config.js @@ -10,22 +10,11 @@ const configTypeDefs = gql` port: Int } - type Meta { - name: String, - value: String, - content: String, - rel: String, - property: String, - href: String - } - type Config { devServer: DevServer, - meta: [Meta], staticRouter: Boolean, optimization: String, prerender: Boolean, - title: String, workspace: String } diff --git a/packages/plugin-graphql/test/cases/query-config/greenwood.config.js b/packages/plugin-graphql/test/cases/query-config/greenwood.config.js index 165689cf4..d74f1de5e 100644 --- a/packages/plugin-graphql/test/cases/query-config/greenwood.config.js +++ b/packages/plugin-graphql/test/cases/query-config/greenwood.config.js @@ -1,7 +1,6 @@ import { greenwoodPluginGraphQL } from '../../../src/index.js'; export default { - title: 'GraphQL ConfigQuery Spec', plugins: [ ...greenwoodPluginGraphQL() diff --git a/packages/plugin-graphql/test/cases/query-config/query-config.spec.js b/packages/plugin-graphql/test/cases/query-config/query-config.spec.js index ce3e4979c..6c257669c 100644 --- a/packages/plugin-graphql/test/cases/query-config/query-config.spec.js +++ b/packages/plugin-graphql/test/cases/query-config/query-config.spec.js @@ -20,7 +20,6 @@ */ import chai from 'chai'; import fs from 'fs'; -import greenwoodConfig from './greenwood.config.js'; import glob from 'glob-promise'; import { JSDOM } from 'jsdom'; import path from 'path'; @@ -31,7 +30,7 @@ import { fileURLToPath, URL } from 'url'; const expect = chai.expect; -describe('Build Greenwood With: ', function() { +xdescribe('Build Greenwood With: ', function() { const LABEL = 'ConfigQuery from GraphQL'; const apolloStateRegex = /window.__APOLLO_STATE__ = true/; const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js'); @@ -67,7 +66,7 @@ describe('Build Greenwood With: ', function() { runSmokeTest(['public', 'index'], LABEL); - describe('displaying config title in the footer using ConfigQuery', function() { + describe('displaying config optimization in the footer using ConfigQuery', function() { let dom; before(async function() { @@ -77,7 +76,7 @@ describe('Build Greenwood With: ', function() { it('should have a