MarkBind / markbind

MarkBind is a tool for generating content-heavy websites from source files in Markdown format
https://markbind.org/
MIT License
135 stars 124 forks source link

Inconsistent reloading of site on updating frontmatter #1001

Closed yash-chowdhary closed 4 years ago

yash-chowdhary commented 4 years ago

What did you do? Please include the actual source code causing the issue.

(same results with footer: footer.md)

<frontmatter>
  layout: default
  pageNav: 2
  pageNavTitle: "Chapters of This Page"
  siteNav: site-nav.md
</frontmatter>

What did you expect to happen? The default layout to take over and the original header/footer in header.md/footer.md to not take effect.

What actually happened? Please include the actual, raw output. The header/footer doesn't get removed. However, if I disconnect the sever and re-run markbind build / markbind serve, the change is reflected i.e. the default layout is rendered instead of the header in header.md.

If this behaviour is intentional, perhaps we can document it under Frontmatter or Page Layouts?

crphang commented 4 years ago

I could replicate it. This behaviour is not intentional. This is because the default in layouts are empty for footer and header.

Try replacing it with:

header.md

<header>
</header>

And it will work.

This happened because since layout default is empty:

Page.prototype.collectPageSection = function (section) {
  const $ = cheerio.load(this.content, { xmlMode: false });
  const pageSection = $(section);
  if (pageSection.length === 0) { // This line of code is executed when header is empty
    return;
  }
  this.pageSectionsHtml[section] = htmlBeautify($.html(section), { indent_size: 2 }).trim(); // As a result page sections is NOT replaced
  pageSection.remove();
  this.content = htmlBeautify($.html(), { indent_size: 2 });
};

We could move towards making our page immutable or page generation idempotent as much as possible to help remove such errors associated to state mutations

Something like this fixes it

Page.prototype.collectAllPageSections = function () {
+ this.pageSectionsHtml = {}; // This resets the pageSectionsHTML whenever we collect.
  this.collectPageSection('header');
  this.collectPageSection(`#${SITE_NAV_ID}`);
  this.collectPageSection('footer');
};
yash-chowdhary commented 4 years ago

Try replacing it with:

header.md

<header>
</header>

We could move towards making our page immutable or page generation idempotent as much as possible to help remove such errors associated to state mutations

Something like this fixes it

Page.prototype.collectAllPageSections = function () {
+ this.pageSectionsHtml = {}; // This resets the pageSectionsHTML whenever we collect.
  this.collectPageSection('header');
  this.collectPageSection(`#${SITE_NAV_ID}`);
  this.collectPageSection('footer');
};

Is there any particular reason that header.md and footer.md (head.md and navigation.md as well) are blank upon initialization? We could go ahead with both the suggested fixes/changes, couldn't we?

yamgent commented 4 years ago

Is there any particular reason that header.md and footer.md (head.md and navigation.md as well) are blank upon initialization? We could go ahead with both the suggested fixes/changes, couldn't we?

It is probably just an oversight, they shouldn't be blank. Yes let's do both.