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">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Title</title>
|
<title>GitBlog.md - Home</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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>
|
</body>
|
||||||
</html>
|
</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)
|
if (err)
|
||||||
return cb(err);
|
return cb(err);
|
||||||
const paths = fileList
|
const paths = fileList
|
||||||
.map((path) =>path.substr(config['data_dir'].length))
|
.map((path) => path.substr(config['data_dir'].length))
|
||||||
.filter((path) =>path.indexOf(config['article']['index']) === path.length - config['article']['index'].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.substr(0, path.length - config['article']['index'].length))
|
||||||
.map((path) =>path.match(/^\/(\d{4})\/(\d{2})\/(\d{2})\/$/))
|
.map((path) => path.match(/^\/(\d{4})\/(\d{2})\/(\d{2})\/$/))
|
||||||
.filter((matches) =>matches && matches.length > 1);
|
.filter((matches) => matches && matches.length > 1);
|
||||||
if (paths.length === 0)
|
if (paths.length === 0)
|
||||||
cb(null, []);
|
cb(null, []);
|
||||||
const list = [];
|
const list = [];
|
||||||
let remaining = 0;
|
let remaining = 0;
|
||||||
paths.forEach((matches) =>{
|
paths.forEach((matches) => {
|
||||||
const article = {
|
const article = {
|
||||||
path: path.join(config['data_dir'], matches[1], matches[2], matches[3], config['article']['index']),
|
path: path.join(matches[1], matches[2], matches[3]),
|
||||||
parent: path.join(config['data_dir'], matches[1], matches[2], matches[3]),
|
realPath: path.join(config['data_dir'], matches[1], matches[2], matches[3]),
|
||||||
year: parseInt(matches[1]),
|
year: parseInt(matches[1]),
|
||||||
month: parseInt(matches[2]),
|
month: parseInt(matches[2]),
|
||||||
day: parseInt(matches[3])
|
day: parseInt(matches[3])
|
||||||
};
|
};
|
||||||
|
article.date = new Date(article.year, article.month, article.day);
|
||||||
remaining++;
|
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)
|
if (err)
|
||||||
return cb(err);
|
return cb(err);
|
||||||
article.title = info.title || config['article']['default_title'];
|
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);
|
list.push(article);
|
||||||
remaining--;
|
remaining--;
|
||||||
if (remaining === 0)
|
if (remaining === 0)
|
||||||
|
|||||||
@@ -225,13 +225,16 @@ describe('Test article fetching', () => {
|
|||||||
expect(list).toBeDefined();
|
expect(list).toBeDefined();
|
||||||
expect(list.length).toBe(1);
|
expect(list.length).toBe(1);
|
||||||
expect(list[0]).toEqual({
|
expect(list[0]).toEqual({
|
||||||
path: file,
|
path: path.join('2019', '05', '05'),
|
||||||
parent:dir,
|
realPath: dir,
|
||||||
year: 2019,
|
year: 2019,
|
||||||
month: 5,
|
month: 5,
|
||||||
day: 5,
|
day: 5,
|
||||||
|
date : new Date(2019,5,5),
|
||||||
title: 'Untitled',
|
title: 'Untitled',
|
||||||
thumbnail: 'default.png'
|
thumbnail: 'default.png',
|
||||||
|
escapedTitle: 'untitled',
|
||||||
|
url: path.join('2019', '05', '05', 'untitled'),
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -241,7 +244,7 @@ describe('Test article fetching', () => {
|
|||||||
const file = path.join(dir, testIndex);
|
const file = path.join(dir, testIndex);
|
||||||
utils.createEmptyDirs([dir]);
|
utils.createEmptyDirs([dir]);
|
||||||
fs.writeFileSync(file, `
|
fs.writeFileSync(file, `
|
||||||
# Title
|
# Title with : info !
|
||||||

|

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