-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-transformer-remark): add excerptAst to be exported as a G…
…raphQL field (#11237) ## Description This PR adds/refactors excerpt + excerptAst (which is a new field) because I personally found it incovenient `gatsby-transformer-remark` not exporting an excerpt field in AST. What I did was basically refactoring by splitting out the resolver of `excerpt` that was internally converting ASTs to HTML to two functions that have similar signatures to the `getHtml()` and `getHtmlAst()`, with some caching feature as well. The tests have been added for these ASTs. Documentation could be added something like this: ```diff diff --git a/packages/gatsby-transformer-remark/README.md b/packages/gatsby-transformer-remark/README.md index 423329b..36a0d59 100644 --- a/packages/gatsby-transformer-remark/README.md +++ b/packages/gatsby-transformer-remark/README.md @@ -119,6 +119,7 @@ By default, excerpts have a maximum length of 140 characters. You can change the node { html excerpt(pruneLength: 500) + excerptAst(pruneLength: 500) } } } @@ -178,14 +181,15 @@ Any file that does not have the given `excerpt_separator` will fall back to the ### Excerpts for non-latin languages -By default, `excerpt` uses `underscore.string/prune` which doesn't handle non-latin characters ([https://github.com/epeli/underscore.string/issues/418](https://github.com/epeli/underscore.string/issues/418)). +By default, `excerpt` and `excerptAst` use `underscore.string/prune` which doesn't handle non-latin characters ([https://github.com/epeli/underscore.string/issues/418](https://github.com/epeli/underscore.string/issues/418)). -If that is the case, you can set `truncate` option on `excerpt` field, like: +If that is the case, you can set `truncate` option on `excerpt` and `excerptAst` field, like: ```graphql { markdownRemark { excerpt(truncate: true) + excerptAst(truncate: true) } } ```
- Loading branch information
Showing
4 changed files
with
552 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.