({ book, data })
| 237 | } |
| 238 | |
| 239 | static async syncContent({ book, data }) { |
| 240 | const { |
| 241 | title, |
| 242 | excerpt = '', |
| 243 | isFree = false, |
| 244 | seoTitle = '', |
| 245 | seoDescription = '', |
| 246 | } = data.attributes; |
| 247 | |
| 248 | const { body, path } = data; |
| 249 | |
| 250 | const chapter = await this.findOne({ |
| 251 | bookId: book._id, |
| 252 | githubFilePath: path, |
| 253 | }).lean(); |
| 254 | |
| 255 | let order; |
| 256 | |
| 257 | if (path === 'introduction.md') { |
| 258 | order = 1; |
| 259 | } else { |
| 260 | order = parseInt(path.match(/[0-9]+/), 10) + 1; |
| 261 | } |
| 262 | |
| 263 | const content = body; |
| 264 | const htmlContent = markdownToHtml(content); |
| 265 | const htmlExcerpt = markdownToHtml(excerpt); |
| 266 | const sections = getSections(content); |
| 267 | |
| 268 | if (!chapter) { |
| 269 | const slug = await generateSlug(this, title, { bookId: book._id }); |
| 270 | |
| 271 | return this.create({ |
| 272 | bookId: book._id, |
| 273 | githubFilePath: path, |
| 274 | title, |
| 275 | slug, |
| 276 | isFree, |
| 277 | content, |
| 278 | htmlContent, |
| 279 | sections, |
| 280 | excerpt, |
| 281 | htmlExcerpt, |
| 282 | order, |
| 283 | seoTitle, |
| 284 | seoDescription, |
| 285 | createdAt: new Date(), |
| 286 | }); |
| 287 | } |
| 288 | |
| 289 | const modifier = { |
| 290 | content, |
| 291 | htmlContent, |
| 292 | sections, |
| 293 | excerpt, |
| 294 | htmlExcerpt, |
| 295 | isFree, |
| 296 | order, |
no test coverage detected