Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Question ] Rendering Chapters #1

Open
jasonsprouse opened this issue Jan 6, 2019 · 1 comment
Open

[ Question ] Rendering Chapters #1

jasonsprouse opened this issue Jan 6, 2019 · 1 comment
Assignees

Comments

@jasonsprouse
Copy link

jasonsprouse commented Jan 6, 2019

Windows 10 Professional
MongoDB.Atlas
Node v8.10.0

All dependencies for Windows have been installed. When I synced Github in Ch. 6 the introduction page md was synced to MongoDB but none of the other demo-book info synced. Now in Ch. 8 the stripe buy button requires the chapter-1.md to test the integration and I'm hung up on rendering anything other than the introduction page. I've signed back in as the Admin and resynced but the alert tells me nothing has changed in the document. I've narrowed down this issue and know of a solution that could be implemented. It is a bit DRY, similar to the pattern shown here, https://www.khanacademy.org/computer-programming/spin-off-of-project-magic-8-ball/6639567377956864. Outside of explicitly stating each path, is there any other implementation other than :

static async syncContent({ book, data }) {
    const {
      title,
      excerpt = '',
      isFree = false,
      seoTitle = '',
      seoDescription = '',
    } = data.attributes;

    const { body, path } = data;

    const chapter = await this.findOne({
      bookId: book.id,
      githubFilePath: path,
    });

    let order;

    if (path === 'introduction.md') {
      order = 1;
    } else {
      order = parseInt(path.match(/[0-9]+/), 10) + 1;
    }

    const content = body;
    const htmlContent = markdownToHtml(content);
    const htmlExcerpt = markdownToHtml(excerpt);
    const sections = getSections(content);

    if (!chapter) {
      const slug = await generateSlug(this, title, { bookId: book._id });

      return this.create({
        bookId: book._id,
        githubFilePath: path,
        title,
        slug,
        isFree,
        content,
        htmlContent,
        sections,
        excerpt,
        htmlExcerpt,
        order,
        seoTitle,
        seoDescription,
        createdAt: new Date(),
      });
    }

    const modifier = {
      content,
      htmlContent,
      sections,
      excerpt,
      htmlExcerpt,
      isFree,
      order,
      seoTitle,
      seoDescription,
    };

    if (title !== chapter.title) {
      modifier.title = title;
      modifier.slug = await generateSlug(this, title, {
        bookId: chapter.bookId,
      });
    }

    return this.updateOne({ _id: chapter._id }, { $set: modifier });
  }
}

in the Mongoose Chapter model you might suggest to sync data between MongoDB and Github?

@tima101
Copy link
Member

tima101 commented Jan 26, 2019

@jasonsprouse Happy to investigate. Would you please create this issue at https://github.com/builderbook/builderbook/issues? This public repo is for dummy data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants