Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat of blog posts #154

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ function buildlocale (locale) {
startswith: require('./scripts/helpers/startswith.js'),
i18n: require('./scripts/helpers/i18n.js'),
changeloglink: require('./scripts/helpers/changeloglink.js'),
strftime: require('./scripts/helpers/strftime.js')
strftime: require('./scripts/helpers/strftime.js'),
summary: require('./scripts/helpers/summary.js')
}
}))
.destination(path.join(__dirname, 'build', locale));
Expand Down
4 changes: 4 additions & 0 deletions layouts/blog-index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<li>
<time datetime="{{ date }}">{{ strftime date "%d %b %y" }}</time>
<a href="/{{../../site.locale}}/{{ path }}/">{{ title }}</a>

<div class="summary">
{{{ summary contents ../../site.locale path }}}
<div>
</li>
{{/if}}
{{/each}}
Expand Down
3 changes: 3 additions & 0 deletions layouts/css/page-modules/_blog-index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
time
margin-right 1em
color $lightgray

.summary
font-size: 75%
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"dependencies": {
"autoprefixer-stylus": "^0.7.1",
"cheerio": "^0.19.0",
"chokidar": "^1.0.5",
"gulp": "^3.9.0",
"handlebars": "^3.0.0",
Expand Down
27 changes: 27 additions & 0 deletions scripts/helpers/summary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const cheerio = require('cheerio');

const SUMMARY_LENGHT = 400;

module.exports = function (contents, locale, path) {
let $ = cheerio.load(contents);

let summary = '';
let child = 1;

$('*').each((i, elem) => {
if (summary.length > SUMMARY_LENGHT) {
summary += `<p><a href='/${locale}/${path}/'>Read more...</a></p>`;
return false;
}

if (elem.parent) {
return;
}

summary += $.html(elem);
})

return `${summary}`;
};