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

Truncating an excerpt leaves html, head and body tags #5

Open
ianhirschfeld opened this issue Dec 31, 2019 · 2 comments
Open

Truncating an excerpt leaves html, head and body tags #5

ianhirschfeld opened this issue Dec 31, 2019 · 2 comments

Comments

@ianhirschfeld
Copy link

Using a modified example from #2 with no replacements and adding truncation:

{
  resolve: `gatsby-plugin-excerpts`,
  options: {
    sources: {
      beheadedDescription: {
        type: 'htmlQuery',
        sourceField: 'description',
        excerptSelector: 'body > *',
        elementReplacements: [],
        truncate: {
          stripTags: true,
          length: 80,
          byWords: true,
          ellipsis: '…'
        },
      },
    },
    sourceSets: {
      beheadDescription: [
        `beheadedDescription`
      ]
    },
    excerpts: {
      processedDescription: {
        type: `html`,
        nodeTypeSourceSet: {
          ContentYaml: `beheadDescription`
        }
      }
    }
  },
}

Produces a result like:

{
  "beheadDescription": "<html><head></head><body>Wherever you are Put your stuff in Dropbox and get to it from your computers, phones, or tablets. Edit docs, automatically add photos, and show off videos from anywhere.Share with confidence Share photos with friends. Work with your team like you&apos;re using a single computer. Everything&apos;s automatically private, so you control who sees what.Safe and secure Even if your phone goes for a swim, your stuff is always safe in Dropbox and can be restored in a snap. Dropbox secures&#x2026;</body></html>"
}

All tags are properly stripped because of the truncate stripTags flag, however html, head, and body are left within the results.

@YoshiWalsh
Copy link
Owner

I agree that this is a bug, but it turns out fixing it is non-trivial and potentially breaking. I have a few ideas, I'll look into it.

@ianhirschfeld
Copy link
Author

Ah ok. It’s not a show stopper for me. I have a workaround for my particular use case. I just wanted to mark it here in case you or someone else ran into it. Thanks again for the quick response!

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

No branches or pull requests

2 participants