Skip to content

Commit

Permalink
PPT模板日期,列表支持日期排序以及作者
Browse files Browse the repository at this point in the history
  • Loading branch information
52cik committed May 27, 2017
1 parent c1c9acc commit cf2725c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
/npm-debug.log

/publish

/.vscode
6 changes: 5 additions & 1 deletion lib/nodePPT.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ function doneTmpl(opts) {
}
var json = require(path.join(libDir, '../package.json'));
opts.version = json.version;
opts.site = json.site;
// opts.site = json.site;
opts.site = 'http://ppt.fed.tm';

var dt = new Date();
opts.date = [dt.getFullYear(), dt.getMonth() + 1, dt.getDate()].join('-').replace(/(?=\b\d\b)/g, '0');

var html = $.renderFile(templateDir + (opts.isHTML ? 'default.ejs' : 'defaultmd.ejs'), opts);

Expand Down
48 changes: 41 additions & 7 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ function pptlist(res, dir, argvObj) {

var curPath = dir;

var count = 0,
list = '';
var count = 0;
var list = [];
//遍历html文件
$.recurse(dir, function(realpath, rootdir, subdir, filename) {
count++;
Expand All @@ -318,7 +318,12 @@ function pptlist(res, dir, argvObj) {
title = filename;
}
var url = filename;
list += '<li><a class="star" href="' + url + '" target="_blank">' + title + '</a></li>';
list.push({
title: title,
speaker: '',
date: '',
html: '<li><a class="star" href="' + url + '" target="_blank">' + title + '</a></li>',
});
}, '', '', function(filename) {
return /\.htm[l]?/.test(filename);
});
Expand All @@ -330,25 +335,54 @@ function pptlist(res, dir, argvObj) {
//第一个是封面
var cover = content.split('[slide]').shift();

var title = md_parser.parseCover(cover).title;
var coverData = md_parser.parseCover(cover);
var title = coverData.title;
var speaker = coverData.speaker;
var date = coverData.date;

if (!title) {
title = filename;
}

var url = '/md/' + filename;
list += '<li><a class="star" href="' + url + '" target="_blank">' + title + '</a>';
list += (argvObj.controller === 'socket' ? '' : '<a href="' + url + '?_multiscreen=1" target="_blank" title="多窗口打开" class="mult-link">多窗口</a><a href="' + url + '?controller=socket" target="_blank" title="用socket远程控制" class="socket-link">远程控制</a>') + '</li>';

// ppt 数据
var data = {
title: title,
speaker: speaker,
date: date,
html: '',
};
data.html += '<li><a class="star" href="' + url + '" target="_blank">' + date + ' -《' + title + '》- ' + speaker + '</a>';
data.html += (argvObj.controller === 'socket' ? '' : '<a href="' + url + '?_multiscreen=1" target="_blank" title="多窗口打开" class="mult-link">多窗口</a><a href="' + url + '?controller=socket" target="_blank" title="用socket远程控制" class="socket-link">远程控制</a>') + '</li>';

list.push(data);
}, '', '', function(filename) {
return /\.(md|markdown)$/.test(filename);
});

var json = require(path.join(__dirname, '../package.json'));

// 排序
list.sort(function (a, b) {
if (a.date === b.date) {
return a.speaker > b.speaker ? -1 : 1;
}

return a.date > b.date ? -1 : 1;
});

// html 处理
var listHtml = '';
list.forEach(function(it) {
listHtml += it.html;
});

var data = {
version: json.version,
site: json.site,
date: Date.now(),
list: list,
list: listHtml,
dir: curPath
};
//渲染模板
Expand Down
1 change: 1 addition & 0 deletions template/defaultmd.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
title: <%= title %>
speaker: <%= speaker %>
date: <%= date %>
url: <%= site %>
transition: cards
files: /js/demo.js,/css/demo.css
Expand Down
106 changes: 32 additions & 74 deletions template/list.ejs
Original file line number Diff line number Diff line change
@@ -1,80 +1,38 @@
<!--
Powered By nodePPT
version: <%=version %>
site: <%=site %>
-->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>nodePPT List</title>
<style>
body{
width: 900px;
margin: 0 auto;
color: #2C3E50;
}
a{
color:#4fc3f7;
text-decoration: none;
}
ol, li{
list-style:none;
padding:0;
margin:0;
}
ol{
-webkit-text-shadow: 1px 1px 1px rgba(201, 201, 201, 0.5);
-moz-text-shadow: 1px 1px 1px rgba(201, 201, 201, 0.5);
-ms-text-shadow: 1px 1px 1px rgba(201, 201, 201, 0.5);
-o-text-shadow: 1px 1px 1px rgba(201, 201, 201, 0.5);
text-shadow: 1px 1px 1px rgba(201, 201, 201, 0.5);
}
li{
font-size: 110%;
font-weight: bold;
padding: .75em 0;
border-bottom:1px dashed #ccc;
}
li:hover{
background-color: #eee;
}
.copyright{
font-weight: normal;
text-align: center;
padding: 0;
margin: 0;
line-height: 24px;
position: fixed;
bottom: 0.5em;
right: 0.5em;
margin-left: -74px;
}
.copyright a{
color: #ea7373;
}
ol a.mult-link, ol a.socket-link{
margin: 0 15px;
}
ol a.mult-link:before, ol a.socket-link:before{
content: '[ ';
color: black;
}
ol a.mult-link:after, ol a.socket-link:after{
content: ' ]';
color: black;
}
ol a.socket-link{
margin: 0 ;
}
</style>
<meta charset="UTF-8">
<title>nodePPT List - TooMee</title>
<style>
html,body{height:100%;}
body{margin:0 auto;width:900px;color:#2C3E50;}
a{color:#4fc3f7;text-decoration:none;}
li,ol{margin:0;padding:0;list-style:none;}
ol{min-height:510px;margin-bottom:40px;text-shadow:1px 1px 1px rgba(201,201,201,.5);-webkit-text-shadow:1px 1px 1px rgba(201,201,201,.5);-moz-text-shadow:1px 1px 1px rgba(201,201,201,.5);-ms-text-shadow:1px 1px 1px rgba(201,201,201,.5);-o-text-shadow:1px 1px 1px rgba(201,201,201,.5);}
li{padding:.75em 0;border-bottom:1px dashed #ccc;font-weight:700;font-size:110%;}
li:hover{background-color:#eee;}
.copyright{margin:auto;padding:0;text-align:center;font-weight:400;line-height:24px;}
.copyright h4{margin:0;}
.copyright a, .copyright code{color:#ea7373;}
ol a.mult-link,ol a.socket-link{margin:0 15px;}
ol a.mult-link:before,ol a.socket-link:before{color:#000;content:'[ ';}
ol a.mult-link:after,ol a.socket-link:after{color:#000;content:' ]';}
ol a.socket-link{margin:0;}
</style>
</head>
<body>
<h4>当前路径:<%-dir %></h4>
<ol>
<%- list %>
</ol>
<h4 class="copyright">Powered by <a title="使用NodePPT" href="<%=site%>" target="_blank">NodePPT <%=version%></a></h4>
<!--
Powered By nodePPT
version: <%=version %>
site: <%=site %>
-->
<h4>当前路径:<%- dir %></h4>

<ol><%- list -%></ol>

<div class="copyright">
<h4>Powered by <a title="使用NodePPT" href="<%=site%>" target="_blank">NodePPT <%=version%></a></h4>
<h4>Modify by TooMee. Install: <code>npm i -g 52cik/nodeppt</code></h4>
</div>
</body>
</html>
</html>

0 comments on commit cf2725c

Please sign in to comment.