YoshiWalsh / gatsby-plugin-excerpts

MIT License
3 stars 1 forks source link

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

Open ianhirschfeld opened 4 years ago

ianhirschfeld commented 4 years ago

Using a modified example from https://github.com/JoshuaWalsh/gatsby-plugin-excerpts/issues/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 commented 4 years ago

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 commented 4 years ago

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!