Skip to content

Commit

Permalink
Tweak some rules around the linting for TIL
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwlchan committed Apr 5, 2024
1 parent cffad95 commit 7afc87d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion front-matter.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"nav_section": {
"description": "Which section of the site this page/post belongs to.",
"type": "string",
"enum": ["contact"]
"enum": ["til", "contact"]
},
"card_image": {
"description": "Complete path to an image that should be used in link previews on social media, e.g. Twitter cards or OpenGraph metadata.",
Expand Down
17 changes: 7 additions & 10 deletions src/_plugins/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,13 @@ def check_yaml_front_matter(src_dir)

errors[md_path] = md_errors unless md_errors.empty?

# This is to test some rules that can't easily be expressed
# in a JSON schema definition.
is_in_post_directory = (
md_path.start_with?('src/_posts/') or
md_path.start_with?('src/_drafts/')
)

errors[md_path] <<= "layout should be 'post'; got #{front_matter['layout']}" if is_in_post_directory && front_matter['layout'] != 'post'

errors[md_path] <<= "layout should be 'page'; got #{front_matter['layout']}" if !is_in_post_directory && front_matter['layout'] != 'page'
if md_path.start_with?('src/_posts/') && md_path.start_with?('src/_drafts') && front_matter['layout'] != 'post'
errors[md_path] <<= "layout should be 'post'; got #{front_matter['layout']}"
elsif md_path.start_with('src/_til/') && front_matter['layout'] != 'til'
errors[md_path] <<= "layout should be 'til'; got #{front_matter['layout']}"
elsif front_matter['layout'] != 'page'
errors[md_path] <<= "layout should be 'page'; got #{front_matter['layout']}"
end
end

report_errors(errors)
Expand Down

0 comments on commit 7afc87d

Please sign in to comment.