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

fix(storefront): strf-9594 loosed frontmatter refex #841

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/utils/frontmatter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const frontmatterRegex = /---\r?\n(?:.|\s)*?\r?\n---\r?\n/g;
const frontmatterRegex = /---[\s\S]+?---/g;

/**
*
Expand Down
20 changes: 20 additions & 0 deletions lib/utils/frontmatter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs');
const { getFrontmatterContent } = require('./frontmatter');

const cwd = process.cwd();

describe('frontmatter', () => {
it('should successfully get frontmatter content fromt file', async () => {
const fileName = `${cwd}/test/_mocks/frontmatter/valid.html`;
const fileContent = await fs.promises.readFile(fileName, { encoding: 'utf-8' });
const frontmatter = getFrontmatterContent(fileContent);
expect(frontmatter).not.toBeNull();
});

it('should return null while getting frontmatter content fromt file', async () => {
const fileName = `${cwd}/test/_mocks/frontmatter/absent.html`;
const fileContent = await fs.promises.readFile(fileName, { encoding: 'utf-8' });
const frontmatter = getFrontmatterContent(fileContent);
expect(frontmatter).toBeNull();
});
});
19 changes: 19 additions & 0 deletions test/_mocks/frontmatter/absent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
// ---
</script>
<div class="main full">
{{#if products.featured}}
{{> components/products/featured products=products.featured columns=theme_settings.homepage_featured_products_column_count}}
{{/if}}
{{{region name="home_below_featured_products"}}}

{{#if products.top_sellers}}
{{> components/products/top products=products.top_sellers columns=theme_settings.homepage_top_products_column_count}}
{{/if}}
{{{region name="home_below_top_products"}}}

{{#if products.new}}
{{> components/products/new products=products.new columns=theme_settings.homepage_new_products_column_count}}
{{/if}}
{{{region name="home_below_new_products"}}}
</div>
45 changes: 45 additions & 0 deletions test/_mocks/frontmatter/valid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
products:
new:
limit: {{theme_settings.homepage_new_products_count}}
featured:
limit: {{theme_settings.homepage_featured_products_count}}
top_sellers:
limit: {{theme_settings.homepage_top_products_count}}
carousel: {{theme_settings.homepage_show_carousel}}
blog:
recent_posts:
limit: {{theme_settings.homepage_blog_posts_count}}
---
{{#partial "hero"}}
{{{region name="home_below_menu"}}}
{{#and carousel carousel.slides.length}}
{{> components/carousel arrows=theme_settings.homepage_show_carousel_arrows play_pause_button=theme_settings.homepage_show_carousel_play_pause_button}}
{{/and}}
{{{region name="home_below_carousel"}}}
{{/partial}}

{{#partial "page"}}

{{#each shipping_messages}}
{{> components/common/alert/alert-info message}}
{{/each}}

<div class="main full">
{{#if products.featured}}
{{> components/products/featured products=products.featured columns=theme_settings.homepage_featured_products_column_count}}
{{/if}}
{{{region name="home_below_featured_products"}}}

{{#if products.top_sellers}}
{{> components/products/top products=products.top_sellers columns=theme_settings.homepage_top_products_column_count}}
{{/if}}
{{{region name="home_below_top_products"}}}

{{#if products.new}}
{{> components/products/new products=products.new columns=theme_settings.homepage_new_products_column_count}}
{{/if}}
{{{region name="home_below_new_products"}}}
</div>
{{/partial}}
{{> layout/base}}