Giter Club home page Giter Club logo

gatsby-plugin-excerpts's People

Contributors

snyk-bot avatar yoshiwalsh avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

luungoc2005

gatsby-plugin-excerpts's Issues

Truncating an excerpt leaves html, head and body tags

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.

Error: TypeError: Cannot read property 'call' of undefined

I'm trying to use this excerpt on html that is coming from markdown within yaml.

Plugins I'm using:

  • gatsby-transformer-yaml-full
  • gatsby-yaml-full-markdown
  • gatsby-plugin-excerpts

Here is an example yaml file:

name: Dropbox
description: !markdown |
  **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.

My excerpts config looks like this:

{
  resolve: `gatsby-plugin-excerpts`,
  options: {
    sources: {
      snippetBlocks: {
        type: 'htmlQuery',
        sourceField: 'description',
        stripSelector: 'a',
        elementReplacements: [
          {
            selector: 'h6',
            replaceWith: 'strong'
          },
          {
            selector: 'h5',
            replaceWith: 'h6'
          },
          {
            selector: 'h4',
            replaceWith: 'h5'
          },
          {
            selector: 'h3',
            replaceWith: 'h4'
          },
          {
            selector: 'h2',
            replaceWith: 'h3'
          },
        ],
      },
      default: {
        type: 'htmlQuery',
        sourceField: 'html',
        excerptSelector: 'html > *',
        ignoreSelector: 'img, .gatsby-highlight',
        stripSelector: 'a',
        elementReplacements: [
          {
            selector: 'h6',
            replaceWith: 'strong'
          },
          {
            selector: 'h5',
            replaceWith: 'h6'
          },
          {
            selector: 'h4',
            replaceWith: 'h5'
          },
          {
            selector: 'h3',
            replaceWith: 'h4'
          },
          {
            selector: 'h2',
            replaceWith: 'h3'
          },
        ],
        truncate: {
          length: 80,
          byWords: true,
          ellipsis: '…'
        },
      }
    },
    sourceSets: {
      markdownHtml: [
        `snippetBlocks`,
        `default`
      ]
    },
    excerpts: {
      snippet: {
        type: `html`,
        nodeTypeSourceSet: {
          ToolkitYaml: `markdownHtml`
        }
      }
    }
  },
}

When running this in the GraphQL explorer my console is outputting:

warn [gatsby-plugin-excerpts] Failed to retrieve field name for source snippetBlocks on node
{"name":"Dropbox","description":"<p><strong>Wherever you are</strong><br>\nPut 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.</p>\n<p><strong>Share with confidence</strong><br>\nShare photos with friends. Work with your team like
you're using a single computer. Everything's automatically private, so you control who sees what.</p>\n<p><strong>Safe
 and secure</strong><br>\nEven if your phone goes for a swim, your stuff is always safe in Dropbox and can be restored
 in a snap. Dropbox secures your files with 256-bit AES encryption and two-step verification.</p>\n<p><strong>Dropbox
for Business</strong><br>\nMillions of people use Dropbox at work. With Dropbox for Business, get the power and
security of Dropbox plus robust admin controls, dedicated support, and all the space you need.</p>\n","id":"69da20e4-3
9cf-5a8e-942e-82bd8bc7aa6a","parent":"6d788dd1-4504-5c96-b52b-79dbf63c0954","children":[],"internal":{"contentDigest":
"a307bad168cc338874d1930aa890d197","type":"ToolkitYaml","counter":40,"owner":"gatsby-transformer-yaml-full"}} . Error:
  TypeError: Cannot read property 'call' of undefined
    at /Users/hirsch/Development/hackdesign-gatsby/node_modules/gatsby-plugin-excerpts/gatsby-node.js:309:81
    at step (/Users/hirsch/Development/hackdesign-gatsby/node_modules/gatsby-plugin-excerpts/gatsby-node.js:148:17)
    at Object.next
(/Users/hirsch/Development/hackdesign-gatsby/node_modules/gatsby-plugin-excerpts/gatsby-node.js:79:14)
    at /Users/hirsch/Development/hackdesign-gatsby/node_modules/gatsby-plugin-excerpts/gatsby-node.js:51:67

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.