File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
packages/gatsby-plugin-mdx Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -562,6 +562,22 @@ export const pageQuery = graphql`
562562`
563563```
564564
565+ ## Troubleshooting
566+
567+ ### Excerpts for non-latin languages
568+
569+ 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 ) ).
570+
571+ If that is the case, you can set ` truncate ` option on ` excerpt ` field, like:
572+
573+ ``` graphql
574+ {
575+ markdownRemark {
576+ excerpt (truncate : true )
577+ }
578+ }
579+ ```
580+
565581## License
566582
567583MIT
Original file line number Diff line number Diff line change 11const _ = require ( `lodash` )
2+ const { GraphQLBoolean } = require ( `gatsby/graphql` )
23const remark = require ( `remark` )
34const english = require ( `retext-english` )
45const remark2retext = require ( `remark-retext` )
@@ -151,8 +152,12 @@ module.exports = (
151152 type : `Int` ,
152153 defaultValue : 140 ,
153154 } ,
155+ truncate : {
156+ type : GraphQLBoolean ,
157+ defaultValue : false ,
158+ } ,
154159 } ,
155- async resolve ( mdxNode , { pruneLength } ) {
160+ async resolve ( mdxNode , { pruneLength, truncate } ) {
156161 if ( mdxNode . excerpt ) {
157162 return Promise . resolve ( mdxNode . excerpt )
158163 }
@@ -166,7 +171,14 @@ module.exports = (
166171 return
167172 } )
168173
169- return prune ( excerptNodes . join ( ` ` ) , pruneLength , `…` )
174+ if ( ! truncate ) {
175+ return prune ( excerptNodes . join ( ` ` ) , pruneLength , `…` )
176+ }
177+
178+ return _ . truncate ( excerptNodes . join ( ` ` ) , {
179+ length : pruneLength ,
180+ omission : `…` ,
181+ } )
170182 } ,
171183 } ,
172184 headings : {
You can’t perform that action at this time.
0 commit comments