Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit e8cfde1

Browse files
committed
支持yaml自定义ejs模板和webslides配置
1 parent c0c04c7 commit e8cfde1

File tree

5 files changed

+58
-26
lines changed

5 files changed

+58
-26
lines changed

packages/nodeppt-parser/index.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,27 @@ const yamlParser = require('./lib/yaml-parser');
1111
const defaults = require('./defaults');
1212

1313
// 模板
14-
const template = fs.readFileSync(path.join(__dirname, './template/index.ejs')).toString();
14+
const defaultTemplate = fs.readFileSync(path.join(__dirname, './template/index.ejs')).toString();
1515
// 这里不要用箭头函数,this 指向问题!
1616
/* eslint-disable space-before-function-paren */
17-
module.exports = function(content) {
18-
/* eslint-enable space-before-function-paren */
17+
module.exports = function (content) {
18+
/* eslint-enable space-before-function-paren */
1919
const {plugins = []} = loaderUtils.getOptions(this);
20+
const resourcePath = this.resourcePath;
2021
const parser = getParser(plugins);
2122

2223
const settings = content.split(/<slide.*>/i)[0];
23-
24+
const yamlSettings = yamlParser(settings);
25+
// 支持baseTemplate,传入ejs模板
26+
let template = defaultTemplate;
27+
if (yamlSettings.baseTemplate && typeof yamlSettings.baseTemplate === 'string') {
28+
const baseTemplate = path.resolve(path.dirname(resourcePath), yamlSettings.baseTemplate);
29+
if (fs.existsSync(baseTemplate)) {
30+
template = fs.readFileSync(baseTemplate).toString();
31+
}
32+
}
2433
// 首部 yaml 设置部分
25-
const globalSettings = defaultDeep(yamlParser(settings), defaults);
34+
const globalSettings = defaultDeep(yamlSettings, defaults);
2635
content = parser(content);
2736

2837
return ejs.render(template, {...globalSettings, content});

packages/nodeppt-parser/template/index.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
</article>
3232
</div>
3333
<% if (hasOwnProperty('plugins') && plugins && plugins.indexOf && ~plugins.indexOf('echarts')) { %>
34-
<script src="https://cdn.staticfile.org/echarts/4.1.0-release/echarts.min.js"></script>
34+
<script src="https://cdn.staticfile.org/echarts/4.8.0/echarts.min.js"></script>
3535
<% } %>
3636
<% if (hasOwnProperty('plugins') && plugins && plugins.indexOf && ~plugins.indexOf('mermaid')) { %>
37-
<script src="https://cdn.staticfile.org/mermaid/8.0.0/mermaid.min.js"></script>
37+
<script src="https://cdn.staticfile.org/mermaid/8.5.2/mermaid.min.js"></script>
3838
<script>mermaid.startOnLoad = false;</script>
3939
<% } %>
4040

packages/nodeppt-serve/config/base.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
/**
22
* @file base
33
*/
4-
const path = require('path');
4+
// const path = require('path');
55
const webpack = require('webpack');
66
const {transformer, formatter} = require('nodeppt-shared-utils');
77
module.exports = (api, options) => {
88
const {version} = api.getNodepptOptions();
9-
api.chainWebpack(webpackConfig => {
9+
api.chainWebpack((webpackConfig) => {
1010
const {getAssetPath, resolveLocal} = require('../lib/utils');
1111
const inlineLimit = 4096;
1212

13-
const genAssetSubPath = dir => {
13+
const genAssetSubPath = (dir) => {
1414
return getAssetPath(options, `${dir}/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`);
1515
};
1616

17-
const genUrlLoaderOptions = dir => {
17+
const genUrlLoaderOptions = (dir) => {
1818
return {
1919
limit: inlineLimit,
2020
// use explicit fallback to avoid regression in url-loader>=1.1.0
2121
fallback: {
2222
loader: 'file-loader',
2323
options: {
2424
name: genAssetSubPath(dir),
25-
esModule: false
26-
}
27-
}
25+
esModule: false,
26+
},
27+
},
2828
};
2929
};
3030
let entryName = 'app';
@@ -63,7 +63,7 @@ module.exports = (api, options) => {
6363
.end()
6464
.use('nodeppt-parser')
6565
.loader(require.resolve('nodeppt-parser'))
66-
.options({plugins: options.plugins})
66+
.options({plugins: options.plugins, template: options.baseTemplate})
6767
.end();
6868

6969
webpackConfig.module
@@ -90,7 +90,7 @@ module.exports = (api, options) => {
9090
.use('file-loader')
9191
.loader(require.resolve('file-loader'))
9292
.options({
93-
name: genAssetSubPath('img')
93+
name: genAssetSubPath('img'),
9494
});
9595

9696
webpackConfig.module
@@ -109,7 +109,7 @@ module.exports = (api, options) => {
109109

110110
webpackConfig.plugin('banner').use(
111111
new webpack.BannerPlugin({
112-
banner: `Created by nodeppt ${version} \n - Install: npm install -g nodeppt\n - Github: https://github.com/ksky521/nodeppt`
112+
banner: `Created by nodeppt ${version} \n - Install: npm install -g nodeppt\n - Github: https://github.com/ksky521/nodeppt`,
113113
})
114114
);
115115

@@ -120,8 +120,8 @@ module.exports = (api, options) => {
120120
webpackConfig.plugin('friendly-errors').use(require('friendly-errors-webpack-plugin'), [
121121
{
122122
additionalTransformers: [transformer],
123-
additionalFormatters: [formatter]
124-
}
123+
additionalFormatters: [formatter],
124+
},
125125
]);
126126

127127
webpackConfig.plugin('progress').use(require('webpack/lib/ProgressPlugin'));

packages/nodeppt/README.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
[![Markpress npm badge](https://nodei.co/npm/nodeppt.png)](https://www.npmjs.com/package/nodeppt)
66

7-
87
**nodeppt 2.0** 基于[webslides](https://github.com/webslides/WebSlides)、webpack、markdown-it、posthtml 重构,[新效果](https://nodeppt.js.org)
98

109
## Install
@@ -95,10 +94,19 @@ plugins:
9594
- css:css 文件数组,放到头部
9695
- prismTheme:prism 配色,取值范围 `['dark', 'coy', 'funky', 'okaidia', 'tomorrow', 'solarizedlight', 'twilight']`
9796
- plugins:目前支持 [echarts](https://echarts.baidu.com/) 和 [katex](https://katex.org) 两个插件
97+
- pluginsOptions:插件的配置
98+
- webslidesOptions:[webslides](https://github.com/webslides/WebSlides/wiki/Core-API#options)配置
99+
100+
**webslidesOptions 对应的是 webslides 的配置,例如开启`autoslide`**:
101+
102+
```yaml
103+
webslidesOptions:
104+
autoslide: 5000
105+
```
98106

99107
#### 插件
100108

101-
目前 nodeppt 支持 [图表 echarts](https://echarts.baidu.com/) ,[流程图 mermaid](https://mermaidjs.github.io/),[数学符号 KaTeX](https://katex.org) 3个插件
109+
目前 nodeppt 支持 [图表 echarts](https://echarts.baidu.com/) ,[流程图 mermaid](https://mermaidjs.github.io/),[数学符号 KaTeX](https://katex.org) 3 个插件
102110

103111
#### echarts
104112

@@ -119,6 +127,7 @@ echarts 主题配色可以直接在`yaml`配置的 js 中引入。echarts 采用
119127
}]
120128
}
121129
```
130+
122131
详见[site/echarts.md](./site/echarts.md)
123132

124133
#### mermaid
@@ -138,6 +147,7 @@ sequenceDiagram
138147
```
139148

140149
详见[site/mermaid.md](./site/mermaid.md)
150+
141151
#### ketex
142152

143153
参考:[markdown-it-katex](https://www.npmjs.com/package/markdown-it-katex)语法
@@ -443,7 +453,7 @@ module.exports = () => ({
443453
integrity: false,
444454
445455
css: {
446-
extract: true
456+
extract: true,
447457
// modules: false,
448458
// localIdentName: '[name]_[local]_[hash:base64:5]',
449459
// sourceMap: false,
@@ -458,7 +468,7 @@ module.exports = () => ({
458468
proxy: null, // string | Object
459469
before: app => {}
460470
*/
461-
}
471+
},
462472
});
463473
```
464474

@@ -477,7 +487,7 @@ module.exports = {
477487
// 分别对应 markdown-it和 posthtml 插件语法
478488
id: 'markdown-xxx',
479489
// 这里的 apply 是插件实际的内容,详细查看 markdown-it和 posthtml 插件开发
480-
apply: () => {}
490+
apply: () => {},
481491
};
482492
```
483493

@@ -498,8 +508,8 @@ window.WSPlugins_ = [
498508
{
499509
id: 'webslide_plugin_name',
500510
// 下面是对应的插件类
501-
apply: class Plugin {}
502-
}
511+
apply: class Plugin {},
512+
},
503513
];
504514
```
505515

site/mermaid.md

+13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ sequenceDiagram
3535
Alice->John: Yes... John, how are you?
3636
```
3737

38+
<slide :class="size-60">
39+
## Mermaid can render state diagrams. {.aligncenter}
40+
41+
```mermaid
42+
stateDiagram-v2
43+
[*] --> Still
44+
Still --> [*]
45+
46+
Still --> Moving
47+
Moving --> Still
48+
Moving --> Crash
49+
Crash --> [*]
50+
```
3851

3952

4053
<slide :class="size-60">

0 commit comments

Comments
 (0)