feat: seo meta + page titles

This commit is contained in:
Nicolas Giard 2018-12-24 17:38:34 -05:00
parent fcee4c0945
commit 10940ca230
14 changed files with 52 additions and 26 deletions

View File

@ -49,15 +49,6 @@
v-model='config.description' v-model='config.description'
prepend-icon='explore' prepend-icon='explore'
) )
v-text-field(
outline
label='Site Keywords'
:counter='255'
v-model='config.keywords'
prepend-icon='explore'
hint='Comma-separated list of keywords.'
persistent-hint
)
v-select.mt-2( v-select.mt-2(
outline outline
label='Meta Robots' label='Meta Robots'
@ -170,7 +161,6 @@ export default {
host: '', host: '',
title: '', title: '',
description: '', description: '',
keywords: '',
robots: [], robots: [],
ga: '', ga: '',
company: '', company: '',
@ -196,7 +186,6 @@ export default {
host: this.config.host || '', host: this.config.host || '',
title: this.config.title || '', title: this.config.title || '',
description: this.config.description || '', description: this.config.description || '',
keywords: this.config.keywords || '',
robots: this.config.robots || [], robots: this.config.robots || [],
ga: this.config.ga || '', ga: this.config.ga || '',
company: this.config.company || '', company: this.config.company || '',

View File

@ -51,6 +51,8 @@ export default {
<style lang='scss'> <style lang='scss'>
.loader-dialog { .loader-dialog {
transition: all .4s ease;
.atom-spinner.is-inline { .atom-spinner.is-inline {
display: inline-block; display: inline-block;
} }

View File

@ -350,10 +350,10 @@ export default {
@include keyframes(loginBgReveal) { @include keyframes(loginBgReveal) {
0% { 0% {
background-position-y: 0; background-position-x: 0;
} }
100% { 100% {
background-position-y: -800px; background-position-x: 800px;
} }
} }

View File

@ -2,7 +2,6 @@ mutation (
$host: String! $host: String!
$title: String! $title: String!
$description: String! $description: String!
$keywords: String!
$robots: [String]! $robots: [String]!
$ga: String! $ga: String!
$company: String! $company: String!
@ -17,7 +16,6 @@ mutation (
host: $host, host: $host,
title: $title, title: $title,
description: $description, description: $description,
keywords: $keywords,
robots: $robots, robots: $robots,
ga: $ga, ga: $ga,
company: $company, company: $company,

View File

@ -4,7 +4,6 @@
host host
title title
description description
keywords
robots robots
ga ga
company company

View File

@ -7,7 +7,17 @@ html
meta(name='theme-color', content='#333333') meta(name='theme-color', content='#333333')
meta(name='msapplication-TileColor', content='#333333') meta(name='msapplication-TileColor', content='#333333')
meta(name='msapplication-TileImage', content='/favicons/ms-icon-144x144.png') meta(name='msapplication-TileImage', content='/favicons/ms-icon-144x144.png')
title= config.title
title= pageMeta.title + ' | ' + config.title
//- SEO / OpenGraph
meta(name='description', content=pageMeta.description)
meta(property='og:title', content=pageMeta.title)
meta(property='og:type', content='website')
meta(property='og:description', content=pageMeta.description)
meta(property='og:image', content=pageMeta.image)
meta(property='og:url', content=pageMeta.url)
meta(property='og:site_name', content=config.title)
//- Favicon //- Favicon
each favsize in [57, 60, 72, 76, 114, 120, 144, 152, 180] each favsize in [57, 60, 72, 76, 114, 120, 144, 152, 180]
@ -17,9 +27,9 @@ html
link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png') link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
//- Site Lang //- Site Properties
script. script.
var siteConfig = !{JSON.stringify({ title: config.title, theme: config.theming.theme, darkMode: config.theming.darkMode, lang: config.lang.code })} var siteConfig = !{JSON.stringify({ title: config.title, theme: config.theming.theme, darkMode: config.theming.darkMode, lang: config.lang.code, company: config.company })}
//- CSS //- CSS
link(type='text/css', rel='stylesheet', href='https://fonts.googleapis.com/icon?family=Roboto:400,500,700|Varela+Round|Source+Code+Pro:400,700|Material+Icons') link(type='text/css', rel='stylesheet', href='https://fonts.googleapis.com/icon?family=Roboto:400,500,700|Varela+Round|Source+Code+Pro:400,700|Material+Icons')

View File

@ -3,11 +3,13 @@
const express = require('express') const express = require('express')
const router = express.Router() const router = express.Router()
const moment = require('moment') const moment = require('moment')
const _ = require('lodash')
/** /**
* Login form * Login form
*/ */
router.get('/login', function (req, res, next) { router.get('/login', function (req, res, next) {
_.set(res.locals, 'pageMeta.title', 'Login')
res.render('login') res.render('login')
}) })
@ -23,6 +25,7 @@ router.get('/logout', function (req, res) {
* Register form * Register form
*/ */
router.get('/register', async (req, res, next) => { router.get('/register', async (req, res, next) => {
_.set(res.locals, 'pageMeta.title', 'Register')
const localStrg = await WIKI.models.authentication.getStrategy('local') const localStrg = await WIKI.models.authentication.getStrategy('local')
if (localStrg.selfRegistration) { if (localStrg.selfRegistration) {
res.render('register') res.render('register')

View File

@ -1,6 +1,7 @@
const express = require('express') const express = require('express')
const router = express.Router() const router = express.Router()
const pageHelper = require('../helpers/page') const pageHelper = require('../helpers/page')
const _ = require('lodash')
/* global WIKI */ /* global WIKI */
@ -16,10 +17,13 @@ router.get(['/e', '/e/*'], async (req, res, next) => {
isPrivate: false isPrivate: false
}) })
if (page) { if (page) {
_.set(res.locals, 'pageMeta.title', `Edit ${page.title}`)
_.set(res.locals, 'pageMeta.description', page.description)
page.mode = 'update' page.mode = 'update'
page.isPublished = (page.isPublished === true || page.isPublished === 1) ? 'true' : 'false' page.isPublished = (page.isPublished === true || page.isPublished === 1) ? 'true' : 'false'
page.content = Buffer.from(page.content).toString('base64') page.content = Buffer.from(page.content).toString('base64')
} else { } else {
_.set(res.locals, 'pageMeta.title', `New Page`)
page = { page = {
path: pageArgs.path, path: pageArgs.path,
localeCode: pageArgs.locale, localeCode: pageArgs.locale,
@ -35,6 +39,7 @@ router.get(['/e', '/e/*'], async (req, res, next) => {
* Administration * Administration
*/ */
router.get(['/a', '/a/*'], (req, res, next) => { router.get(['/a', '/a/*'], (req, res, next) => {
_.set(res.locals, 'pageMeta.title', 'Admin')
res.render('admin') res.render('admin')
}) })
@ -42,6 +47,7 @@ router.get(['/a', '/a/*'], (req, res, next) => {
* Profile * Profile
*/ */
router.get(['/p', '/p/*'], (req, res, next) => { router.get(['/p', '/p/*'], (req, res, next) => {
_.set(res.locals, 'pageMeta.title', 'User Profile')
res.render('profile') res.render('profile')
}) })
@ -57,6 +63,8 @@ router.get(['/h', '/h/*'], async (req, res, next) => {
isPrivate: false isPrivate: false
}) })
if (page) { if (page) {
_.set(res.locals, 'pageMeta.title', page.title)
_.set(res.locals, 'pageMeta.description', page.description)
res.render('history', { page }) res.render('history', { page })
} else { } else {
res.redirect(`/${pageArgs.path}`) res.redirect(`/${pageArgs.path}`)
@ -75,6 +83,8 @@ router.get(['/s', '/s/*'], async (req, res, next) => {
isPrivate: false isPrivate: false
}) })
if (page) { if (page) {
_.set(res.locals, 'pageMeta.title', page.title)
_.set(res.locals, 'pageMeta.description', page.description)
res.render('source', { page }) res.render('source', { page })
} else { } else {
res.redirect(`/${pageArgs.path}`) res.redirect(`/${pageArgs.path}`)
@ -93,6 +103,8 @@ router.get('/*', async (req, res, next) => {
isPrivate: false isPrivate: false
}) })
if (page) { if (page) {
_.set(res.locals, 'pageMeta.title', page.title)
_.set(res.locals, 'pageMeta.description', page.description)
const sidebar = await WIKI.models.navigation.getTree({ cache: true }) const sidebar = await WIKI.models.navigation.getTree({ cache: true })
res.render('page', { page, sidebar }) res.render('page', { page, sidebar })
} else if (pageArgs.path === 'home') { } else if (pageArgs.path === 'home') {

View File

@ -30,7 +30,6 @@ module.exports = {
WIKI.config.company = args.company WIKI.config.company = args.company
WIKI.config.seo = { WIKI.config.seo = {
description: args.description, description: args.description,
keywords: args.keywords,
robots: args.robots, robots: args.robots,
ga: args.ga ga: args.ga
} }

View File

@ -27,7 +27,6 @@ type SiteMutation {
host: String! host: String!
title: String! title: String!
description: String! description: String!
keywords: String!
robots: [String]! robots: [String]!
ga: String! ga: String!
company: String! company: String!
@ -47,7 +46,6 @@ type SiteConfig {
host: String! host: String!
title: String! title: String!
description: String! description: String!
keywords: String!
robots: [String]! robots: [String]!
ga: String! ga: String!
company: String! company: String!

View File

@ -100,6 +100,12 @@ module.exports = async () => {
app.locals.moment = require('moment') app.locals.moment = require('moment')
app.locals.moment.locale(WIKI.config.lang.code) app.locals.moment.locale(WIKI.config.lang.code)
app.locals.config = WIKI.config app.locals.config = WIKI.config
app.locals.pageMeta = {
title: '',
description: WIKI.config.description,
image: '',
url: '/'
}
// ---------------------------------------- // ----------------------------------------
// HMR (Dev Mode Only) // HMR (Dev Mode Only)

View File

@ -15,6 +15,7 @@ module.exports = function (req, res, next) {
let query = req.url.slice(req.path.length) || '' let query = req.url.slice(req.path.length) || ''
res.redirect(301, req.path.slice(0, -1) + query) res.redirect(301, req.path.slice(0, -1) + query)
} else { } else {
_.set(res.locals, 'pageMeta.url', `${WIKI.config.host}${req.path}`)
return next() return next()
} }
} }

View File

@ -133,7 +133,6 @@ module.exports = () => {
_.set(WIKI.config, 'public', false) _.set(WIKI.config, 'public', false)
_.set(WIKI.config, 'seo', { _.set(WIKI.config, 'seo', {
description: '', description: '',
keywords: '',
robots: ['index', 'follow'], robots: ['index', 'follow'],
ga: '' ga: ''
}) })

View File

@ -7,7 +7,17 @@ html
meta(name='theme-color', content='#333333') meta(name='theme-color', content='#333333')
meta(name='msapplication-TileColor', content='#333333') meta(name='msapplication-TileColor', content='#333333')
meta(name='msapplication-TileImage', content='/favicons/ms-icon-144x144.png') meta(name='msapplication-TileImage', content='/favicons/ms-icon-144x144.png')
title= config.title
title= pageMeta.title + ' | ' + config.title
//- SEO / OpenGraph
meta(name='description', content=pageMeta.description)
meta(property='og:title', content=pageMeta.title)
meta(property='og:type', content='website')
meta(property='og:description', content=pageMeta.description)
meta(property='og:image', content=pageMeta.image)
meta(property='og:url', content=pageMeta.url)
meta(property='og:site_name', content=config.title)
//- Favicon //- Favicon
each favsize in [57, 60, 72, 76, 114, 120, 144, 152, 180] each favsize in [57, 60, 72, 76, 114, 120, 144, 152, 180]
@ -17,9 +27,9 @@ html
link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png') link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
//- Site Lang //- Site Properties
script. script.
var siteConfig = !{JSON.stringify({ title: config.title, theme: config.theming.theme, darkMode: config.theming.darkMode, lang: config.lang.code })} var siteConfig = !{JSON.stringify({ title: config.title, theme: config.theming.theme, darkMode: config.theming.darkMode, lang: config.lang.code, company: config.company })}
//- CSS //- CSS
link(type='text/css', rel='stylesheet', href='https://fonts.googleapis.com/icon?family=Roboto:400,500,700|Varela+Round|Source+Code+Pro:400,700|Material+Icons') link(type='text/css', rel='stylesheet', href='https://fonts.googleapis.com/icon?family=Roboto:400,500,700|Varela+Round|Source+Code+Pro:400,700|Material+Icons')