index.js
738 Bytes
'use strict';
// 页面seo相关属性的配置文件
const seoMap = require('./seoConfig');
/**
* 设置seo相关的数据,包括title, keywords, description
* @param {undefined}
* @return {Function} 中间件函数,用于给res.locals对象添加属性
*/
module.exports = () => {
return (req, res, next) => {
if (!req.xhr) {
let seo;
if (req.tdk) {
seo = {
title: req.tdk[1],
keywords: req.tdk[2],
description: req.tdk[3]
};
} else {
seo = seoMap[req.path] || seoMap['/'];
}
Object.assign(res.locals, seo);
}
next();
};
};