Commit ec80671 1 parent 84a37d2 commit ec80671 Copy full SHA for ec80671
File tree 2 files changed +30
-2
lines changed
packages/gatsby-plugin-mdx
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`
562
562
`
563
563
```
564
564
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
+
565
581
## License
566
582
567
583
MIT
Original file line number Diff line number Diff line change 1
1
const _ = require ( `lodash` )
2
+ const { GraphQLBoolean } = require ( `gatsby/graphql` )
2
3
const remark = require ( `remark` )
3
4
const english = require ( `retext-english` )
4
5
const remark2retext = require ( `remark-retext` )
@@ -151,8 +152,12 @@ module.exports = (
151
152
type : `Int` ,
152
153
defaultValue : 140 ,
153
154
} ,
155
+ truncate : {
156
+ type : GraphQLBoolean ,
157
+ defaultValue : false ,
158
+ } ,
154
159
} ,
155
- async resolve ( mdxNode , { pruneLength } ) {
160
+ async resolve ( mdxNode , { pruneLength, truncate } ) {
156
161
if ( mdxNode . excerpt ) {
157
162
return Promise . resolve ( mdxNode . excerpt )
158
163
}
@@ -166,7 +171,14 @@ module.exports = (
166
171
return
167
172
} )
168
173
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
+ } )
170
182
} ,
171
183
} ,
172
184
headings : {
You can’t perform that action at this time.
0 commit comments