diff --git a/packages/cli/src/data/schema/graph.js b/packages/cli/src/data/schema/graph.js
index 7840af4c5..f1c9f1797 100644
--- a/packages/cli/src/data/schema/graph.js
+++ b/packages/cli/src/data/schema/graph.js
@@ -22,16 +22,16 @@ const getPagesFromGraph = async (root, query, context) => {
graph
.forEach((page) => {
- const { route, mdFile, fileName, template } = page;
- const id = page.label;
+ const { route, mdFile, fileName, template, title } = page;
const { label } = getDeriveMetaFromRoute(route);
+ const id = page.label;
pages.push({
id,
filePath: mdFile,
fileName,
template,
- title: label,
+ title: title !== '' ? title : label,
link: route
});
});
@@ -69,11 +69,11 @@ const getChildrenFromParentRoute = async (root, query, context) => {
graph
.forEach((page) => {
- const { route, mdFile, fileName, template } = page;
+ const { route, mdFile, fileName, template, title } = page;
+ const { label } = getDeriveMetaFromRoute(route);
const root = route.split('/')[1];
if (root.indexOf(parent) >= 0) {
- const { label } = getDeriveMetaFromRoute(route);
const id = page.label;
pages.push({
@@ -81,7 +81,7 @@ const getChildrenFromParentRoute = async (root, query, context) => {
filePath: mdFile,
fileName,
template,
- title: label,
+ title: title !== '' ? title : label,
link: route
});
}
diff --git a/packages/cli/src/lifecycles/config.js b/packages/cli/src/lifecycles/config.js
index 892d5a829..514453b64 100644
--- a/packages/cli/src/lifecycles/config.js
+++ b/packages/cli/src/lifecycles/config.js
@@ -9,7 +9,7 @@ let defaultConfig = {
host: 'localhost'
},
publicPath: '/',
- title: 'Greenwood App',
+ title: 'My App',
meta: [],
plugins: [],
themeFile: 'theme.css'
diff --git a/packages/cli/src/lifecycles/graph.js b/packages/cli/src/lifecycles/graph.js
index b457e5629..f9045ec0d 100644
--- a/packages/cli/src/lifecycles/graph.js
+++ b/packages/cli/src/lifecycles/graph.js
@@ -72,7 +72,7 @@ const createGraphFromPages = async (pagesDir, config) => {
label = label || generateLabelHash(filePath);
// set
element text, override with markdown title
- title = title || config.title;
+ title = title || '';
/*
* Variable Definitions
diff --git a/packages/cli/src/plugins/meta.js b/packages/cli/src/plugins/meta.js
index 2e44ce269..b8c529a7b 100644
--- a/packages/cli/src/plugins/meta.js
+++ b/packages/cli/src/plugins/meta.js
@@ -56,14 +56,6 @@ class meta extends LitElement {
header.appendChild(meta);
}
});
-
- // handle tag
- let title = document.createElement('title');
-
- title.innerText = this.attributes.title;
- const oldTitle = document.head.querySelector('title');
-
- header.replaceChild(title, oldTitle);
}
}
}
diff --git a/packages/cli/src/templates/app-template.js b/packages/cli/src/templates/app-template.js
index eee98601c..fc59bfc66 100644
--- a/packages/cli/src/templates/app-template.js
+++ b/packages/cli/src/templates/app-template.js
@@ -3,6 +3,9 @@ import { connectRouter } from 'lit-redux-router';
import { applyMiddleware, createStore, compose as origCompose, combineReducers } from 'redux';
import { lazyReducerEnhancer } from 'pwa-helpers/lazy-reducer-enhancer.js';
import thunk from 'redux-thunk';
+import client from '@greenwood/cli/data/client';
+import ConfigQuery from '@greenwood/cli/data/queries/config';
+import GraphQuery from '@greenwood/cli/data/queries/graph';
// eslint-disable-next-line no-underscore-dangle
const compose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || origCompose;
@@ -17,6 +20,37 @@ import './list';
connectRouter(store);
class AppComponent extends LitElement {
+
+ async connectedCallback() {
+ super.connectedCallback();
+ const route = window.location.pathname;
+ const response = await Promise.all([
+ await client.query({
+ query: ConfigQuery
+ }),
+ await client.query({
+ query: GraphQuery
+ })
+ ]);
+ const { config } = response[0].data;
+ const currentPage = response[1].data.graph.filter((page) => {
+ return route === page.link;
+ })[0];
+ const currentPageTitleSuffix = currentPage.link === '/'
+ ? ''
+ : ` - ${currentPage.title}`;
+ const fullTitle = `${config.title}${currentPageTitleSuffix}`;
+
+ this.setDocoumentTitle(fullTitle);
+ }
+
+ setDocoumentTitle(title) {
+ const head = document.head;
+ const titleElement = head.getElementsByTagName('title')[0];
+
+ titleElement.innerHTML = title;
+ }
+
render() {
return html`
MYROUTES
diff --git a/packages/cli/src/templates/index.html b/packages/cli/src/templates/index.html
index b6ba9e499..fc7ca20f1 100644
--- a/packages/cli/src/templates/index.html
+++ b/packages/cli/src/templates/index.html
@@ -1,7 +1,7 @@
- My App
+
@@ -20,6 +20,7 @@
+
\ No newline at end of file
diff --git a/packages/cli/test/cases/build.config.title/build.config.title.spec.js b/packages/cli/test/cases/build.config.title/build.config.title.spec.js
index e60ad2c82..90f28767e 100644
--- a/packages/cli/test/cases/build.config.title/build.config.title.spec.js
+++ b/packages/cli/test/cases/build.config.title/build.config.title.spec.js
@@ -27,6 +27,7 @@ const expect = require('chai').expect;
const runSmokeTest = require('../../../../../test/smoke-test');
const TestBed = require('../../../../../test/test-bed');
+const configTitle = require('./greenwood.config').title;
const mainBundleScriptRegex = /index.*.bundle\.js/;
describe('Build Greenwood With: ', function() {
@@ -45,7 +46,6 @@ describe('Build Greenwood With: ', function() {
runSmokeTest(['public', 'not-found', 'hello'], LABEL);
describe('Custom Title', function() {
- const indexPageTitle = 'My Custom Greenwood App';
const indexPageHeading = 'Greenwood';
const indexPageBody = 'This is the home page built by Greenwood. Make your own pages in src/pages/index.js!';
let dom;
@@ -61,7 +61,7 @@ describe('Build Greenwood With: ', function() {
it('should have our custom config meta tag in the ', function() {
const title = dom.window.document.querySelector('head title').textContent;
- expect(title).to.be.equal(indexPageTitle);
+ expect(title).to.be.equal(configTitle);
});
// rest of index smoke-test because is changed for this case
@@ -116,7 +116,7 @@ describe('Build Greenwood With: ', function() {
it('should have a overridden meta tag in the using markdown front-matter', function() {
const title = dom.window.document.querySelector('head title').textContent;
- expect(title).to.be.equal(helloPageTitle);
+ expect(title).to.be.equal(`${configTitle} - ${helloPageTitle}`);
});
});
});
diff --git a/packages/cli/test/cases/build.default.workspace-template-app/build.default.workspace-template-app.spec.js b/packages/cli/test/cases/build.default.workspace-template-app/build.default.workspace-template-app.spec.js
index 57565a319..215e45bd5 100644
--- a/packages/cli/test/cases/build.default.workspace-template-app/build.default.workspace-template-app.spec.js
+++ b/packages/cli/test/cases/build.default.workspace-template-app/build.default.workspace-template-app.spec.js
@@ -51,10 +51,10 @@ describe('Build Greenwood With: ', function() {
dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'index.html'));
});
- it('should have a tag in the ', function() {
+ it('should have the default config title in the tag in the ', function() {
const title = dom.window.document.querySelector('head title').textContent;
- expect(title).to.be.equal('Greenwood App');
+ expect(title).to.be.equal('My App');
});
it('should have one