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

Add specs to test permalink summary truncation #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RyanSnodgrass
Copy link

@RyanSnodgrass RyanSnodgrass commented Dec 18, 2024

This is a PR to validate a bug in summary behavior. The behavior expected for summaries is as follows:

  1. Truncation by length
    • article.summary is the first x number of characters.
    • aritcle.body has all content including the first x characters.
  2. Separator such as READMORE
    • article.summary is everything before separator
    • article.body has all content AFTER separator
    • separator string has been stripped out

This PR adds some tests that shows when in scenario 2 using a separator: article.body only strips out the separator but leaves in the summary content.

As per documentation:

The blogging extension looks for the string READMORE in your article body and shows only the content before this text on the homepage. On the permalink page, this data is then stripped out.

Looking around, I think most people don't use the separator. Instead the preferred method seems to be to add another front matter field to use for summary.

I tried a quick fix at Middleman::Blog::BlogArticle

-        content.sub!(blog_options.summary_separator, '') unless opts[:keep_separator]
+        content = content.split(blog_options.summary_separator).last unless opts[:keep_separator]

But this chopped the rendered html document in half instead.

I'm tossing this PR up in the hopes someone more knowledgable can present a fix.

I think it needs to be done further up the chain. Before the markdown content is rendered. Because middleman-core handles markdown rendering in a separate repo I'm not sure it's wise to directly edit that file for the edge case of blogging. Maybe monkeypatch that class to strip the summary content before rendering? If we monkeypatched into the content before rendering, we might be able to remove Nokogiri dependency. Since then we'd have access to the text from the markdown file before it gets rendered into html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant