Home minimal EJS template
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Error <%= error %></title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Error <%= error %> at path <%= path %></h1>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,9 +2,22 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<title>GitBlog.md - Home</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<main>
|
||||
<h1>GitBlog.md</h1>
|
||||
A static blog using Markdown pulled from your git repository
|
||||
<h2>Articles in this blog :</h2>
|
||||
<% articles.forEach((article) => { %>
|
||||
<div class="article">
|
||||
<h3><%- `<a href="${article.url}">${article.title}</a>`%> (<small><%= `${article.day}/${article.month}/${article.year}`%></small>)</h3>
|
||||
<% if(article.thumbnail){%>
|
||||
<%- `<img alt="thumbnail" src=${article.thumbnail}>`%>
|
||||
<% }%>
|
||||
</div>
|
||||
<% }); %>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,18 @@
|
||||
main {
|
||||
max-width: 70ch;
|
||||
padding: 2ch;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.article a, .article a:visited{
|
||||
color:black;
|
||||
}
|
||||
|
||||
.article a:visited{
|
||||
color:black;
|
||||
}
|
||||
|
||||
.article img{
|
||||
max-width:100%;
|
||||
max-height:10vh;
|
||||
}
|
||||
+13
-10
@@ -54,29 +54,32 @@ module.exports = (config) => {
|
||||
if (err)
|
||||
return cb(err);
|
||||
const paths = fileList
|
||||
.map((path) =>path.substr(config['data_dir'].length))
|
||||
.filter((path) =>path.indexOf(config['article']['index']) === path.length - config['article']['index'].length)
|
||||
.map((path) =>path.substr(0, path.length - config['article']['index'].length))
|
||||
.map((path) =>path.match(/^\/(\d{4})\/(\d{2})\/(\d{2})\/$/))
|
||||
.filter((matches) =>matches && matches.length > 1);
|
||||
.map((path) => path.substr(config['data_dir'].length))
|
||||
.filter((path) => path.indexOf(config['article']['index']) === path.length - config['article']['index'].length)
|
||||
.map((path) => path.substr(0, path.length - config['article']['index'].length))
|
||||
.map((path) => path.match(/^\/(\d{4})\/(\d{2})\/(\d{2})\/$/))
|
||||
.filter((matches) => matches && matches.length > 1);
|
||||
if (paths.length === 0)
|
||||
cb(null, []);
|
||||
const list = [];
|
||||
let remaining = 0;
|
||||
paths.forEach((matches) =>{
|
||||
paths.forEach((matches) => {
|
||||
const article = {
|
||||
path: path.join(config['data_dir'], matches[1], matches[2], matches[3], config['article']['index']),
|
||||
parent: path.join(config['data_dir'], matches[1], matches[2], matches[3]),
|
||||
path: path.join(matches[1], matches[2], matches[3]),
|
||||
realPath: path.join(config['data_dir'], matches[1], matches[2], matches[3]),
|
||||
year: parseInt(matches[1]),
|
||||
month: parseInt(matches[2]),
|
||||
day: parseInt(matches[3])
|
||||
};
|
||||
article.date = new Date(article.year, article.month, article.day);
|
||||
remaining++;
|
||||
readIndexFile(article.path, config['article']['thumbnail_tag'], (err, info) => {
|
||||
readIndexFile(path.join(article.realPath, config['article']['index']), config['article']['thumbnail_tag'], (err, info) => {
|
||||
if (err)
|
||||
return cb(err);
|
||||
article.title = info.title || config['article']['default_title'];
|
||||
article.thumbnail = info.thumbnail ? path.join(article.parent, info.thumbnail) : config['article']['default_thumbnail'];
|
||||
article.thumbnail = info.thumbnail ? path.join(article.path, info.thumbnail) : config['article']['default_thumbnail'];
|
||||
article.escapedTitle = article.title.toLowerCase().replace(/[^\w]/gm, ' ').trim().replace(/ /gm, '_');
|
||||
article.url = path.join(article.path, article.escapedTitle);
|
||||
list.push(article);
|
||||
remaining--;
|
||||
if (remaining === 0)
|
||||
|
||||
@@ -225,13 +225,16 @@ describe('Test article fetching', () => {
|
||||
expect(list).toBeDefined();
|
||||
expect(list.length).toBe(1);
|
||||
expect(list[0]).toEqual({
|
||||
path: file,
|
||||
parent:dir,
|
||||
path: path.join('2019', '05', '05'),
|
||||
realPath: dir,
|
||||
year: 2019,
|
||||
month: 5,
|
||||
day: 5,
|
||||
date : new Date(2019,5,5),
|
||||
title: 'Untitled',
|
||||
thumbnail: 'default.png'
|
||||
thumbnail: 'default.png',
|
||||
escapedTitle: 'untitled',
|
||||
url: path.join('2019', '05', '05', 'untitled'),
|
||||
});
|
||||
done();
|
||||
});
|
||||
@@ -241,7 +244,7 @@ describe('Test article fetching', () => {
|
||||
const file = path.join(dir, testIndex);
|
||||
utils.createEmptyDirs([dir]);
|
||||
fs.writeFileSync(file, `
|
||||
# Title
|
||||
# Title with : info !
|
||||

|
||||
this is some text
|
||||
`);
|
||||
@@ -250,13 +253,16 @@ describe('Test article fetching', () => {
|
||||
expect(list).toBeDefined();
|
||||
expect(list.length).toBe(1);
|
||||
expect(list[0]).toEqual({
|
||||
path: file,
|
||||
parent:dir,
|
||||
path: path.join('2019', '05', '05'),
|
||||
realPath: dir,
|
||||
year: 2019,
|
||||
month: 5,
|
||||
day: 5,
|
||||
title: 'Title',
|
||||
thumbnail: path.join(dataDir, '2019', '05', '05', './thumbnail.jpg')
|
||||
date : new Date(2019,5,5),
|
||||
title: 'Title with : info !',
|
||||
thumbnail: path.join('2019', '05', '05', './thumbnail.jpg'),
|
||||
escapedTitle: 'title_with___info',
|
||||
url: path.join('2019', '05', '05', 'title_with___info'),
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user