Skip to content
Permalink
Browse files

Fixes summary bug

  • Loading branch information
davidmerfield committed Jan 7, 2020
1 parent 06bf032 commit 3f41b3cc3b7ec094dbffeeb1bfead1727a2f8d7a
Showing with 22 additions and 11 deletions.
  1. +13 −11 app/build/prepare/summary.js
  2. +9 −0 app/build/prepare/tests/summary.js
@@ -4,7 +4,18 @@ var puncs = "?.!:,".split("");
var MAX_LENGTH = 150;
var he = require("he");

// since the summary is often used
// {{}} which is encoded by mustache
// we have to decode it in advance
// because the HTML has already been
// decoded by pandoc...!
function normalize (str) {
return he.decode(str).replace(/\s/g, " ").trim()
}

function summary($, title) {
var summary;

// We ignore the text content of
// these tags for the summary
// we only care about the content
@@ -20,13 +31,11 @@ function summary($, title) {
$(this).append(" ");
});

debug("title:", title);

var summary = $(":root").text();
title = normalize(title)
summary = normalize($(":root").text())

if (summary.length > MAX_LENGTH) {
summary = summary.slice(0, MAX_LENGTH);

summary = summary.trim();

// and go to last whole word
@@ -52,13 +61,6 @@ function summary($, title) {

summary = summary.trim();

// since the summary is often used
// {{}} which is encoded by mustache
// we have to decode it in advance
// because the HTML has already been
// decoded by pandoc...!
summary = he.decode(summary);

return summary;
}

@@ -38,6 +38,15 @@ describe("summary", function() {
).toEqual("Hello");
});

it("handles html entities in the title", function() {
expect(
this.summary({
html: "<p>Supercharge Your Workflow with&nbsp;Sync.com</p><p>Foo</p>",
title: "Supercharge Your Workflow with Sync.com"
})
).toEqual("Foo");
});

it("does not contain the text of the title", function() {
expect(
this.summary({

0 comments on commit 3f41b3c

Please sign in to comment.
You can’t perform that action at this time.