MCPcopy Create free account
hub / github.com/async-labs/builderbook / syncContent

Method syncContent

server/models/Chapter.js:239–333  ·  view source on GitHub ↗
({ book, data })

Source from the content-addressed store, hash-verified

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,

Callers 2

syncOneChapterMethod · 0.45
syncAllChaptersMethod · 0.45

Calls 3

markdownToHtmlFunction · 0.70
getSectionsFunction · 0.70
generateSlugFunction · 0.50

Tested by

no test coverage detected