yoshiwalsh / gatsby-plugin-excerpts Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
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're using a single computer. Everything'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…</body></html>"
}
All tags are properly stripped because of the truncate stripTags
flag, however html
, head
, and body
are left within the results.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.