feat: 添加评论功能

This commit is contained in:
neo 2021-03-16 14:58:28 +08:00
parent d1fc19cf23
commit 69316d469d
4 changed files with 68 additions and 12 deletions

42
.dumi/theme/comment.ts Normal file
View File

@ -0,0 +1,42 @@
import { IApi } from 'dumi';
export default (api: IApi) => {
api.describe({
key: 'valine',
config: {
schema(joi) {
return joi.object();
},
},
});
const { valine = {} } = api.userConfig;
const { appId, appKey, el = '#vcomments' } = valine || {};
api.logger.log('insert Valine');
const valineScript = () => {
return `
(function(){
var script = document.createElement('script');
var m = document.getElementsByTagName('script')[0];
script.src = '//unpkg.com/valine/dist/Valine.min.js';
script.async = 'async';
script.addEventListener('load', function () {
new Valine({
el: '${el}',
appId: '${appId}',
appKey: '${appKey}'
})
}, false);
m.parentNode.insertBefore(script, m)
})();
`;
};
api.addHTMLScripts(() => [
{
content: valineScript(),
},
]);
};

View File

@ -102,18 +102,23 @@ const Layout: React.FC<IRouteComponentProps> = ({ children, location }) => {
<div className="__dumi-default-layout-content">
{children}
{!showHero && !showFeatures && meta.filePath && !meta.gapless && (
<div className="__dumi-default-layout-footer-meta">
{repoPlatform && (
<Link to={`${repoUrl}/edit/${branch}/${meta.filePath}`}>
{isCN
? `${repoPlatform} 上编辑此页`
: `Edit this doc on ${repoPlatform}`}
</Link>
)}
<span data-updated-text={isCN ? '最后更新时间:' : 'Last update: '}>
{updatedTime}
</span>
</div>
<>
<div className="__dumi-default-layout-footer-meta">
{repoPlatform && (
<Link to={`${repoUrl}/edit/${branch}/${meta.filePath}`}>
{isCN
? `${repoPlatform} 上编辑此页`
: `Edit this doc on ${repoPlatform}`}
</Link>
)}
<span
data-updated-text={isCN ? '最后更新时间:' : 'Last update: '}
>
{updatedTime}
</span>
</div>
<div id="vcomments"></div>
</>
)}
{(showHero || showFeatures) && meta.footer && (
<div

View File

@ -316,3 +316,7 @@ body {
color: #b0b1ba;
}
}
#vcomments {
margin-top: 20px;
}

View File

@ -87,6 +87,11 @@ export default defineConfig({
// mode: 'string',
// staticMarkup: false,
},
valine: {
appId: 'Ke6Uq74Gi6sdTxcDu4nJ6sdw-MdYXbMMI',
appKey: 'VtFD26towQ1JQxB9tLHd8odg',
},
plugins: ['./.dumi/theme/comment.ts'],
exportStatic: {},
// more config: https://d.umijs.org/config
});