diff --git a/build.js b/build.js index ff9b3d108e50d..2ed1aabe5a84f 100755 --- a/build.js +++ b/build.js @@ -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)); diff --git a/layouts/blog-index.hbs b/layouts/blog-index.hbs index 1d37a708e838b..6b08ec18b033d 100644 --- a/layouts/blog-index.hbs +++ b/layouts/blog-index.hbs @@ -14,6 +14,10 @@
  • {{ title }} + +
    + {{{ summary contents ../../site.locale path }}} +
  • {{/if}} {{/each}} diff --git a/layouts/css/page-modules/_blog-index.styl b/layouts/css/page-modules/_blog-index.styl index b736bcabad260..f2df8e181f848 100644 --- a/layouts/css/page-modules/_blog-index.styl +++ b/layouts/css/page-modules/_blog-index.styl @@ -2,3 +2,6 @@ time margin-right 1em color $lightgray + + .summary + font-size: 75% diff --git a/package.json b/package.json index ba983254d4473..9d9a2df04b5ce 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/helpers/summary.js b/scripts/helpers/summary.js new file mode 100644 index 0000000000000..db3326d9f5a0b --- /dev/null +++ b/scripts/helpers/summary.js @@ -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 += `

    Read more...

    `; + return false; + } + + if (elem.parent) { + return; + } + + summary += $.html(elem); + }) + + return `${summary}`; +};