├── .bundle └── config ├── .devcontainer └── devcontainer.json ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── config.yml ├── dependabot.yml ├── funding.yml ├── no-response.yml ├── release-drafter.yml ├── settings.yml ├── stale.yml └── workflows │ ├── ci.yml │ └── codeql-analysis.yml ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .rubocop_todo.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE.md ├── README.md ├── docs ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── SECURITY.md ├── jekyll-optional-front-matter.gemspec ├── lib ├── jekyll-optional-front-matter.rb └── jekyll-optional-front-matter │ ├── generator.rb │ └── version.rb ├── script ├── bootstrap └── cibuild └── spec ├── fixtures └── site │ ├── .github │ └── ISSUE_TEMPLATE.md │ ├── CONTRIBUTING │ ├── another-file.markdown │ ├── file.md │ ├── index.md │ └── readme.md ├── jekyll-optional-front-matter ├── content_spec.rb └── generator_spec.rb └── spec_helper.rb /.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_PATH: "vendor/bundle" 3 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the 2 | // README at: https://github.com/devcontainers/templates/tree/main/src/ruby 3 | { 4 | "name": "Ruby", 5 | // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile 6 | "image": "mcr.microsoft.com/devcontainers/ruby:1-3.4-bullseye" 7 | 8 | // Features to add to the dev container. More info: https://containers.dev/features. 9 | // "features": {}, 10 | 11 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 12 | // "forwardPorts": [], 13 | 14 | // Use 'postCreateCommand' to run commands after the container is created. 15 | // "postCreateCommand": "ruby --version", 16 | 17 | // Configure tool-specific properties. 18 | // "customizations": {}, 19 | 20 | // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. 21 | // "remoteUser": "root" 22 | } 23 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Require @benbalter's :+1: for changes to the .github repo-config files 2 | # mainly due to https://github.com/probot/settings privilege escalation 3 | .github/* @benbalter 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | ### Describe the bug 8 | 9 | A clear and concise description of what the bug is. 10 | 11 | ### Steps to reproduce the behavior 12 | 13 | 1. Go to '...' 14 | 2. Click on '....' 15 | 3. Scroll down to '....' 16 | 4. See error 17 | 18 | ### Expected behavior 19 | 20 | A clear and concise description of what you expected to happen. 21 | 22 | ### Screenshots 23 | 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | ### Additional context 27 | 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | ### Is your feature request related to a problem? Please describe the problem you're trying to solve. 8 | 9 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 10 | 11 | ### Describe the solution you'd like 12 | 13 | A clear and concise description of what you want to happen. 14 | 15 | ### Describe alternatives you've considered 16 | 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | ### Additional context 20 | 21 | Add any other context or screenshots about the feature request here. 22 | -------------------------------------------------------------------------------- /.github/config.yml: -------------------------------------------------------------------------------- 1 | # Behaviorbot config. See https://github.com/behaviorbot/ for more information. 2 | # Note: Please Don't edit this file directly. 3 | # Edit https://github.com/benbalter/shared-community-files instead. 4 | 5 | # Configuration for update-docs - https://github.com/behaviorbot/update-docs 6 | updateDocsComment: "Thanks for the pull request! If you are making any changes to the user-facing functionality, please be sure to update the documentation in the `README` or `docs/` folder alongside your change. :heart:" 7 | 8 | # Configuration for request-info - https://github.com/behaviorbot/request-info 9 | requestInfoReplyComment: Thanks for this. Do you mind providing a bit more information about what problem you're trying to solve? 10 | requestInfoLabelToAdd: more-information-needed 11 | 12 | # Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome 13 | #newIssueWelcomeComment: > 14 | # Welcome! 15 | 16 | # Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome 17 | newPRWelcomeComment: Welcome! Congrats on your first pull request to Jekyll Optional Front Matter. If you haven't already, please be sure to check out [the contributing guidelines](https://github.com/benbalter/jekyll-optional-front-matter/blob/master/docs/CONTRIBUTING.md). 18 | 19 | # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge 20 | firstPRMergeComment: "Congrats on getting your first pull request to Jekyll Optional Front Matter merged! Without amazing humans like you submitting pull requests, we couldn’t run this project. You rock! :tada:

If you're interested in tackling another bug or feature, take a look at [the open issues](https://github.com/benbalter/jekyll-optional-front-matter/issues), especially those [labeled `help wanted`](https://github.com/benbalter/jekyll-optional-front-matter/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)." 21 | 22 | # Bug workaround 23 | contact_links: [] 24 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for more information: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | # https://containers.dev/guide/dependabot 6 | 7 | version: 2 8 | updates: 9 | - package-ecosystem: "devcontainers" 10 | directory: "/" 11 | schedule: 12 | interval: weekly 13 | - package-ecosystem: bundler 14 | directory: / 15 | schedule: 16 | interval: weekly -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | patreon: benbalter 2 | -------------------------------------------------------------------------------- /.github/no-response.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-no-response - https://github.com/probot/no-response 2 | # Note: Please Don't edit this file directly. 3 | # Edit https://github.com/benbalter/shared-community-files instead. 4 | 5 | # Number of days of inactivity before an Issue is closed for lack of response 6 | daysUntilClose: 14 7 | # Label requiring a response 8 | responseRequiredLabel: more-information-needed 9 | # Comment to post when closing an Issue for lack of response. Set to `false` to disable 10 | closeComment: > 11 | This issue has been automatically closed because there has been no response 12 | to our request for more information from the original author. With only the 13 | information that is currently in the issue, we don't have enough information 14 | to take action. Please reach out if you have or find the answers we need so 15 | that we can investigate further. 16 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | template: | 2 | ## What's Changed 3 | 4 | $CHANGES 5 | -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | # Repository settings set via https://github.com/probot/settings 2 | # Note: Please Don't edit this file directly. 3 | # Edit https://github.com/benbalter/shared-community-files instead. 4 | 5 | repository: 6 | has_issues: true 7 | has_wiki: false 8 | has_projects: false 9 | has_downloads: false 10 | 11 | labels: 12 | - name: help wanted 13 | oldname: help-wanted 14 | color: 0e8a16 15 | - name: more-information-needed 16 | color: d93f0b 17 | - name: bug 18 | color: b60205 19 | - name: feature 20 | color: 1d76db 21 | - name: good first issue 22 | color: "5319e7" 23 | 24 | # Not currently implemented by probot/settings, but manually implemented in script/deploy 25 | branch_protection: 26 | restrictions: null 27 | enforce_admins: false 28 | required_status_checks: 29 | strict: true 30 | contexts: 31 | - "continuous-integration/travis-ci" 32 | required_pull_request_reviews: 33 | require_code_owner_reviews: true 34 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | # Note: Please Don't edit this file directly. 3 | # Edit https://github.com/benbalter/shared-community-files instead. 4 | 5 | # Number of days of inactivity before an Issue or Pull Request becomes stale 6 | daysUntilStale: 60 7 | 8 | # Number of days of inactivity before a stale Issue or Pull Request is closed 9 | daysUntilClose: 7 10 | 11 | # Issues or Pull Requests with these labels will never be considered stale 12 | exemptLabels: 13 | - pinned 14 | - security 15 | 16 | # Label to use when marking as stale 17 | staleLabel: wontfix 18 | 19 | # Comment to post when marking as stale. Set to `false` to disable 20 | markComment: > 21 | This issue has been automatically marked as stale because it has not had 22 | recent activity. It will be closed if no further activity occurs. Thank you 23 | for your contributions. 24 | 25 | # Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable 26 | closeComment: false 27 | 28 | # Limit to only `issues` or `pulls` 29 | # only: issues 30 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | test: 11 | 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | ruby-version: ['2.7', '3.0'] 16 | jekyll-version: ["~> 3.0", "~> 4.0"] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | 21 | - name: Set up Ruby 22 | uses: ruby/setup-ruby@v1 23 | with: 24 | ruby-version: ${{ matrix.ruby-version }} 25 | bundler-cache: true 26 | env: 27 | JEKYLL_VERSION: ${{ matrix.jekyll-version }} 28 | 29 | - name: Run tests 30 | run: script/cibuild 31 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '39 4 * * 1' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'ruby' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v2 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v1 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v1 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v1 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | spec/examples.txt 2 | _site 3 | *.gem 4 | Gemfile.lock 5 | spec/fixtures/site/.jekyll-cache/ 6 | vendor/ 7 | .bundle/ 8 | spec/fixtures/tmp/.jekyll-cache/ -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: .rubocop_todo.yml 2 | 3 | require: 4 | - rubocop-jekyll 5 | - rubocop-performance 6 | - rubocop-rspec 7 | 8 | inherit_gem: 9 | rubocop-jekyll: .rubocop.yml 10 | 11 | AllCops: 12 | Exclude: 13 | - vendor/**/* 14 | NewCops: enable 15 | 16 | Metrics/BlockLength: 17 | Exclude: 18 | - spec/**/* 19 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config` 3 | # on 2025-05-20 22:24:06 UTC using RuboCop version 1.57.2. 4 | # The point is for the user to remove these configuration records 5 | # one by one as the offenses are removed from the code base. 6 | # Note that changes in the inspected code, or installation of new 7 | # versions of RuboCop, may require this file to be generated again. 8 | 9 | # Offense count: 1 10 | # Configuration parameters: Severity, Include. 11 | # Include: **/*.gemspec 12 | Gemspec/RequiredRubyVersion: 13 | Exclude: 14 | - 'jekyll-optional-front-matter.gemspec' 15 | 16 | # Offense count: 6 17 | Jekyll/NoPutsAllowed: 18 | Exclude: 19 | - 'spec/jekyll-optional-front-matter/content_spec.rb' 20 | 21 | # Offense count: 15 22 | # Configuration parameters: Prefixes, AllowedPatterns. 23 | # Prefixes: when, with, without 24 | RSpec/ContextWording: 25 | Exclude: 26 | - 'spec/jekyll-optional-front-matter/content_spec.rb' 27 | - 'spec/jekyll-optional-front-matter/generator_spec.rb' 28 | 29 | # Offense count: 3 30 | # Configuration parameters: CountAsOne. 31 | RSpec/ExampleLength: 32 | Max: 7 33 | 34 | # Offense count: 2 35 | # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. 36 | # Include: **/*_spec*rb*, **/spec/**/* 37 | RSpec/FilePath: 38 | Exclude: 39 | - 'spec/jekyll-optional-front-matter/content_spec.rb' 40 | - 'spec/jekyll-optional-front-matter/generator_spec.rb' 41 | 42 | # Offense count: 15 43 | RSpec/MultipleExpectations: 44 | Max: 5 45 | 46 | # Offense count: 17 47 | # Configuration parameters: AllowSubject. 48 | RSpec/MultipleMemoizedHelpers: 49 | Max: 10 50 | 51 | # Offense count: 2 52 | # Configuration parameters: AllowedGroups. 53 | RSpec/NestedGroups: 54 | Max: 4 55 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## Unreleased 4 | 5 | * Fixed issue where `page.content` contained Markdown text rather than HTML for pages without front matter. The plugin now converts Markdown content to HTML immediately when adding pages to the site. -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gemspec 6 | 7 | gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"] 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Ben Balter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jekyll Optional Front Matter 2 | 3 | A Jekyll plugin to make front matter optional for Markdown files 4 | 5 | [![CI](https://github.com/benbalter/jekyll-optional-front-matter/actions/workflows/ci.yml/badge.svg)](https://github.com/benbalter/jekyll-optional-front-matter/actions/workflows/ci.yml) 6 | 7 | ## What it does 8 | 9 | Out of the box, Jekyll requires that any markdown file have YAML front matter (key/value pairs separated by two sets of three dashes) in order to be processed and converted to HTML. 10 | 11 | While that behavior may be helpful for large, complex sites, sometimes it's easier to simply add a plain markdown file and have it render without fanfare. 12 | 13 | This plugin does just that. Any Markdown file in your site's source will be treated as a Page and rendered as HTML, even if it doesn't have YAML front matter. 14 | 15 | ## Content Conversion 16 | 17 | The plugin automatically converts Markdown content to HTML when adding pages without front matter to the site. This ensures that `page.content` contains properly formatted HTML rather than raw Markdown, making it compatible with themes and plugins that expect HTML content during site generation. 18 | 19 | ## Usage 20 | 21 | 1. Add the following to your site's Gemfile: 22 | ```ruby 23 | group :jekyll_plugins do 24 | gem 'jekyll-optional-front-matter' 25 | end 26 | ``` 27 | 2. Install the plugin. 28 | - Using Bundler. 29 | ```bash 30 | $ bundler install 31 | ``` 32 | - Using Gem. 33 | ```bash 34 | $ # Install in your user's home directory. 35 | $ gem install jekyll-optional-front-matter --user-install 36 | $ # Install for root user. 37 | $ sudo gem install jekyll-optional-front-matter 38 | ``` 39 | 3. Add the following to your site's config file: 40 | ```yml 41 | plugins: 42 | - jekyll-optional-front-matter 43 | ``` 44 | 45 | Note: If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`. 46 | 47 | ## One potential gotcha 48 | 49 | In order to preserve backwards compatibility, the plugin does not recognize [a short list of common meta files](https://github.com/benbalter/jekyll-optional-front-matter/blob/master/lib/jekyll-optional-front-matter.rb#L4). 50 | 51 | If you want Markdown files like your README, CONTRIBUTING file, CODE_OF_CONDUCT, or LICENSE, etc., you'll need to explicitly add YAML front matter to the file, or add it to your config's list of `include` files, e.g.: 52 | 53 | ```yml 54 | include: 55 | - CONTRIBUTING.md 56 | - README.md 57 | ``` 58 | 59 | ## Configuration 60 | You can configure this plugin in `_config.yml` by adding to the `optional_front_matter` key. 61 | 62 | ### Removing originals 63 | 64 | By default the original markdown files will be included as static pages in the output. To remove them from the output, set the `remove_originals` key to `true`: 65 | 66 | ```yml 67 | optional_front_matter: 68 | remove_originals: true 69 | ``` 70 | 71 | ### Disabling 72 | 73 | Even if the plugin is enabled (e.g., via the `:jekyll_plugins` group in your Gemfile) you can disable it by adding the following to your site's config: 74 | 75 | ```yml 76 | optional_front_matter: 77 | enabled: false 78 | ``` 79 | -------------------------------------------------------------------------------- /docs/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ben@balter.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Jekyll Optional Front Matter 2 | 3 | Hi there! We're thrilled that you'd like to contribute to Jekyll Optional Front Matter. Your help is essential for keeping it great. 4 | 5 | Jekyll Optional Front Matter is an open source project supported by the efforts of an entire community and built one contribution at a time by users like you. We'd love for you to get involved. Whatever your level of skill or however much time you can give, your contribution is greatly appreciated. There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests, helping other users by commenting on issues, or writing code which can be incorporated into Jekyll Optional Front Matter itself. 6 | 7 | Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue, assessing changes, and helping you finalize your pull requests. 8 | 9 | 10 | 11 | ## How to report a bug 12 | 13 | Think you found a bug? Please check [the list of open issues](https://github.com/benbalter/jekyll-optional-front-matter/issues) to see if your bug has already been reported. If it hasn't please [submit a new issue](https://github.com/benbalter/jekyll-optional-front-matter/issues/new). 14 | 15 | Here are a few tips for writing *great* bug reports: 16 | 17 | * Describe the specific problem (e.g., "widget doesn't turn clockwise" versus "getting an error") 18 | * Include the steps to reproduce the bug, what you expected to happen, and what happened instead 19 | * Check that you are using the latest version of the project and its dependencies 20 | * Include what version of the project your using, as well as any relevant dependencies 21 | * Only include one bug per issue. If you have discovered two bugs, please file two issues 22 | * Include screenshots or screencasts whenever possible 23 | * Even if you don't know how to fix the bug, including a failing test may help others track it down 24 | 25 | **If you find a security vulnerability, do not open an issue. Please email ben@balter.com instead.** 26 | 27 | ## How to suggest a feature or enhancement 28 | 29 | If you find yourself wishing for a feature that doesn't exist in Jekyll Optional Front Matter, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Jekyll Optional Front Matter has today have been added because our users saw the need. 30 | 31 | Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and goals of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible, including describing the problem you're trying to solve. 32 | 33 | [Open an issue](https://github.com/benbalter/jekyll-optional-front-matter/issues/new) which describes the feature you would like to see, why you want it, how it should work, etc. 34 | 35 | 36 | 37 | ## Your first contribution 38 | 39 | We'd love for you to contribute to the project. Unsure where to begin contributing to Jekyll Optional Front Matter? You can start by looking through these "good first issue" and "help wanted" issues: 40 | 41 | * [Good first issues](https://github.com/benbalter/jekyll-optional-front-matter/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) - issues which should only require a few lines of code and a test or two 42 | * [Help wanted issues](https://github.com/benbalter/jekyll-optional-front-matter/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) - issues which may be a bit more involved, but are specifically seeking community contributions 43 | 44 | *p.s. Feel free to ask for help; everyone is a beginner at first* :smiley_cat: 45 | 46 | ## How to propose changes 47 | 48 | Here's a few general guidelines for proposing changes: 49 | 50 | * If you are changing any user-facing functionality, please be sure to update the documentation 51 | * If you are adding a new behavior or changing an existing behavior, please be sure to update the corresponding test(s) 52 | * Each pull request should implement **one** feature or bug fix. If you want to add or fix more than one thing, submit more than one pull request 53 | * Do not commit changes to files that are irrelevant to your feature or bug fix 54 | * Don't bump the version number in your pull request (it will be bumped prior to release) 55 | * Write [a good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) 56 | 57 | At a high level, [the process for proposing changes](https://guides.github.com/introduction/flow/) is: 58 | 59 | 1. [Fork](https://github.com/benbalter/jekyll-optional-front-matter/fork) and clone the project 60 | 2. Configure and install the dependencies: `script/bootstrap` 61 | 3. Make sure the tests pass on your machine: `script/cibuild` 62 | 4. Create a descriptively named branch: `git checkout -b my-branch-name` 63 | 5. Make your change, add tests and documentation, and make sure the tests still pass 64 | 6. Push to your fork and [submit a pull request](https://github.com/benbalter/jekyll-optional-front-matter/compare) describing your change 65 | 7. Pat your self on the back and wait for your pull request to be reviewed and merged 66 | 67 | **Interesting in submitting your first Pull Request?** It's easy! You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github) 68 | 69 | ## Bootstrapping your local development environment 70 | 71 | `script/bootstrap` 72 | 73 | ## Running tests 74 | 75 | `script/cibuild` 76 | 77 | ## Code of conduct 78 | 79 | This project is governed by [the Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. 80 | 81 | ## Additional Resources 82 | 83 | * [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/) 84 | * [Using Pull Requests](https://help.github.com/articles/using-pull-requests/) 85 | * [GitHub Help](https://help.github.com) 86 | -------------------------------------------------------------------------------- /docs/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please email [ben@balter.com](mailto:ben@balter.com). 4 | -------------------------------------------------------------------------------- /jekyll-optional-front-matter.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.unshift File.expand_path("lib", __dir__) 4 | require "jekyll-optional-front-matter/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "jekyll-optional-front-matter" 8 | s.version = JekyllOptionalFrontMatter::VERSION 9 | s.authors = ["Ben Balter"] 10 | s.email = ["ben.balter@github.com"] 11 | s.homepage = "https://github.com/benbalter/jekyll-optional-front-matter" 12 | s.summary = "A Jekyll plugin to make front matter optional for Markdown files" 13 | 14 | s.files = `git ls-files app lib`.split("\n") 15 | s.platform = Gem::Platform::RUBY 16 | s.require_paths = ["lib"] 17 | s.license = "MIT" 18 | s.required_ruby_version = ">= 2.5" 19 | 20 | s.add_runtime_dependency "jekyll", ">= 3.0", "< 5.0" 21 | s.add_development_dependency "kramdown-parser-gfm", "~> 1.0" 22 | s.add_development_dependency "rspec", "~> 3.5" 23 | s.add_development_dependency "rubocop", "~> 1.18" 24 | s.add_development_dependency "rubocop-jekyll", "~> 0.10" 25 | s.add_development_dependency "rubocop-performance", "~> 1.5" 26 | s.add_development_dependency "rubocop-rspec", "2.21.0" 27 | end 28 | -------------------------------------------------------------------------------- /lib/jekyll-optional-front-matter.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll" 4 | require "jekyll-optional-front-matter/generator" 5 | 6 | module JekyllOptionalFrontMatter 7 | # Case-insensitive array of filenames to exclude. All files must first 8 | # match the config-defined list of markdown extensions. If you'd like one 9 | # of these files included in your site, simply add YAML front matter to it. 10 | FILENAME_BLACKLIST = %w( 11 | README 12 | LICENSE 13 | LICENCE 14 | COPYING 15 | CODE_OF_CONDUCT 16 | CONTRIBUTING 17 | ISSUE_TEMPLATE 18 | PULL_REQUEST_TEMPLATE 19 | ).freeze 20 | end 21 | -------------------------------------------------------------------------------- /lib/jekyll-optional-front-matter/generator.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module JekyllOptionalFrontMatter 4 | class Generator < Jekyll::Generator 5 | attr_accessor :site 6 | 7 | safe true 8 | priority :normal 9 | 10 | CONFIG_KEY = "optional_front_matter" 11 | ENABLED_KEY = "enabled" 12 | CLEANUP_KEY = "remove_originals" 13 | 14 | def initialize(site) 15 | @site = site 16 | end 17 | 18 | def generate(site) 19 | @site = site 20 | return if disabled? 21 | 22 | # Add pages to the site 23 | pages_to_add.each do |page| 24 | # Pre-convert the content of pages without front matter to ensure 25 | # page.content contains HTML instead of Markdown 26 | convert_content(page) 27 | site.pages << page 28 | end 29 | 30 | site.static_files -= static_files_to_remove if cleanup? 31 | end 32 | 33 | private 34 | 35 | # Convert markdown content to HTML for the page 36 | def convert_content(page) 37 | renderer = Jekyll::Renderer.new(site, page) 38 | page.content = renderer.convert(page.content) 39 | end 40 | 41 | # An array of Jekyll::Pages to add, *excluding* blacklisted files 42 | def pages_to_add 43 | pages.reject { |page| blacklisted?(page) } 44 | end 45 | 46 | # An array of Jekyll::StaticFile's, *excluding* blacklisted files 47 | def static_files_to_remove 48 | markdown_files.reject { |page| blacklisted?(page) } 49 | end 50 | 51 | # An array of potential Jekyll::Pages to add, *including* blacklisted files 52 | def pages 53 | markdown_files.map { |static_file| page_from_static_file(static_file) } 54 | end 55 | 56 | # An array of Jekyll::StaticFile's with a site-defined markdown extension 57 | def markdown_files 58 | site.static_files.select { |file| markdown_converter.matches(file.extname) } 59 | end 60 | 61 | # Given a Jekyll::StaticFile, returns the file as a Jekyll::Page 62 | def page_from_static_file(static_file) 63 | base = static_file.instance_variable_get(:@base) 64 | dir = static_file.instance_variable_get(:@dir) 65 | name = static_file.instance_variable_get(:@name) 66 | Jekyll::Page.new(site, base, dir, name) 67 | end 68 | 69 | # Does the given Jekyll::Page match our filename blacklist? 70 | def blacklisted?(page) 71 | return false if whitelisted?(page) 72 | 73 | FILENAME_BLACKLIST.include?(page.basename.upcase) 74 | end 75 | 76 | def whitelisted?(page) 77 | return false unless site.config["include"].is_a? Array 78 | 79 | entry_filter.included?(page.relative_path) 80 | end 81 | 82 | def markdown_converter 83 | @markdown_converter ||= site.find_converter_instance(Jekyll::Converters::Markdown) 84 | end 85 | 86 | def entry_filter 87 | @entry_filter ||= Jekyll::EntryFilter.new(site) 88 | end 89 | 90 | def option(key) 91 | site.config[CONFIG_KEY] && site.config[CONFIG_KEY][key] 92 | end 93 | 94 | def disabled? 95 | option(ENABLED_KEY) == false || site.config["require_front_matter"] 96 | end 97 | 98 | def cleanup? 99 | option(CLEANUP_KEY) == true || site.config["require_front_matter"] 100 | end 101 | end 102 | end 103 | -------------------------------------------------------------------------------- /lib/jekyll-optional-front-matter/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module JekyllOptionalFrontMatter 4 | VERSION = "0.3.2" 5 | end 6 | -------------------------------------------------------------------------------- /script/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | bundle install 6 | -------------------------------------------------------------------------------- /script/cibuild: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | bundle exec rspec 6 | bundle exec rubocop -S -D 7 | bundle exec gem build jekyll-optional-front-matter.gemspec 8 | -------------------------------------------------------------------------------- /spec/fixtures/site/.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Issue template 2 | -------------------------------------------------------------------------------- /spec/fixtures/site/CONTRIBUTING: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | -------------------------------------------------------------------------------- /spec/fixtures/site/another-file.markdown: -------------------------------------------------------------------------------- 1 | # Another file 2 | -------------------------------------------------------------------------------- /spec/fixtures/site/file.md: -------------------------------------------------------------------------------- 1 | # File 2 | -------------------------------------------------------------------------------- /spec/fixtures/site/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: / 3 | --- 4 | 5 | # Index 6 | -------------------------------------------------------------------------------- /spec/fixtures/site/readme.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | -------------------------------------------------------------------------------- /spec/jekyll-optional-front-matter/content_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | describe JekyllOptionalFrontMatter::Generator do 4 | let(:site) { fixture_site("site") } 5 | let(:generator) { described_class.new(site) } 6 | let(:markdown_files) { generator.send(:markdown_files) } 7 | let(:pages) { generator.send(:pages) } 8 | let(:pages_to_add) { generator.send(:pages_to_add) } 9 | 10 | before do 11 | site.reset 12 | site.read 13 | end 14 | 15 | context "before site processing" do 16 | it "has markdown in the content of pages before generator runs" do 17 | # Find the file.md static file 18 | file_md = markdown_files.find { |f| f.name == "file.md" } 19 | 20 | # Create a page without running the generator 21 | page = generator.send(:page_from_static_file, file_md) 22 | puts "Before generator - Page content: #{page.content.inspect}" 23 | 24 | # The content should be markdown at this point 25 | expect(page.content).to eq("# File\n") 26 | end 27 | end 28 | 29 | context "after generator runs" do 30 | before do 31 | generator.generate(site) 32 | end 33 | 34 | it "converts markdown content to HTML for pages without front matter" do 35 | # Get a page that has been added by the plugin (without front matter) 36 | page = site.pages.find { |p| p.name == "file.md" } 37 | puts "After generator - Page without FM content: #{page.content.inspect}" 38 | 39 | # The content should be HTML after the generator runs 40 | expect(page.content).not_to eq("# File\n") 41 | expect(page.content).to include("File") 78 | 79 | # The content property should also be HTML, not markdown 80 | expect(page.content).not_to eq("# File\n") 81 | expect(page.content).to include("#{file.capitalize.tr("-", " ")}\n" 83 | end 84 | 85 | it "has a .html extension" do 86 | expect(path).to be_an_existing_file 87 | end 88 | 89 | it "renders markdown to HTML" do 90 | expect(expected_content).to eql(content) 91 | end 92 | end 93 | end 94 | end 95 | 96 | context "when disabled" do 97 | let(:site) do 98 | fixture_site("site", "optional_front_matter" => { "enabled" => false }) 99 | end 100 | 101 | context "generating" do 102 | before { generator.generate(site) } 103 | 104 | it "doesn't add the pages to the site" do 105 | expect(site.pages.count).to be(1) 106 | end 107 | end 108 | end 109 | 110 | context "when explicitly enabled" do 111 | let(:site) do 112 | fixture_site("site", "optional_front_matter" => { "enabled" => true }) 113 | end 114 | 115 | context "generating" do 116 | before { generator.generate(site) } 117 | 118 | it "does add the pages to the site" do 119 | expect(site.pages.count).to be(3) 120 | end 121 | end 122 | end 123 | 124 | context "blacklist" do 125 | let(:site) { fixture_site("site", "include" => ["foo.md"]) } 126 | 127 | %w( 128 | README.md 129 | readme.markdown 130 | LICENSE.mkdn 131 | licence.md 132 | COPYING.md 133 | CODE_OF_CONDUCT.md 134 | CONTRIBUTING.markdown 135 | ISSUE_TEMPLATE.md 136 | PULL_REQUEST_TEMPLATE.md 137 | vendor/jekyll/README.md 138 | ).each do |filename| 139 | it "matches #{filename}" do 140 | with_page(filename) do |page| 141 | expect(generator.send(:blacklisted?, page)).to be(true) 142 | expect(generator.send(:whitelisted?, page)).to be(false) 143 | end 144 | end 145 | end 146 | 147 | %w(index.md INDEX.markdown).each do |filename| 148 | it "doesn't match #{filename}" do 149 | with_page(filename) do |page| 150 | expect(generator.send(:blacklisted?, page)).to be(false) 151 | expect(generator.send(:whitelisted?, page)).to be(false) 152 | end 153 | end 154 | end 155 | 156 | context "whitelist" do 157 | let(:site) { fixture_site("site", "include" => ["CONTRIBUTING.md"]) } 158 | 159 | it "whitelists whitelisted files" do 160 | with_page("CONTRIBUTING.md") do |page| 161 | expect(generator.send(:blacklisted?, page)).to be(false) 162 | expect(generator.send(:whitelisted?, page)).to be(true) 163 | end 164 | end 165 | end 166 | end 167 | 168 | context "cleanup" do 169 | let(:site) do 170 | fixture_site("site", "optional_front_matter" => { "remove_originals" => true }) 171 | end 172 | 173 | context "generating" do 174 | before { generator.generate(site) } 175 | 176 | it "adds the pages to the site" do 177 | expect(site.pages.count).to be(3) 178 | names = site.pages.map(&:name) 179 | expect(names).not_to include("readme.md") 180 | expect(names).to include("file.md") 181 | expect(names).to include("another-file.markdown") 182 | expect(names).to include("index.md") 183 | end 184 | 185 | it "removes the originals" do 186 | names = site.static_files.map(&:relative_path) 187 | expect(names).not_to include("/file.md") 188 | expect(names).not_to include("/another-file.markdown") 189 | expect(names).not_to include("/index.md") 190 | end 191 | 192 | it "does not remove blacklisted static files" do 193 | expect(site.static_files.count).to be(2) 194 | names = site.static_files.map(&:relative_path) 195 | expect(names).to include("/readme.md") 196 | expect(names).to include("/CONTRIBUTING") 197 | end 198 | end 199 | end 200 | 201 | context "legacy" do 202 | context "when disabled" do 203 | let(:site) { fixture_site("site", "require_front_matter" => true) } 204 | 205 | context "generating" do 206 | before { generator.generate(site) } 207 | 208 | it "doesn't add the pages to the site" do 209 | expect(site.pages.count).to be(1) 210 | end 211 | end 212 | end 213 | 214 | context "when explicitly enabled" do 215 | let(:site) { fixture_site("site", "require_front_matter" => false) } 216 | 217 | context "generating" do 218 | before { generator.generate(site) } 219 | 220 | it "does add the pages to the site" do 221 | expect(site.pages.count).to be(3) 222 | end 223 | end 224 | end 225 | end 226 | end 227 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll-optional-front-matter" 4 | require "fileutils" 5 | 6 | RSpec.configure do |config| 7 | config.expect_with :rspec do |expectations| 8 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 9 | end 10 | 11 | config.mock_with :rspec do |mocks| 12 | mocks.verify_partial_doubles = true 13 | end 14 | 15 | config.shared_context_metadata_behavior = :apply_to_host_groups 16 | config.example_status_persistence_file_path = "spec/examples.txt" 17 | 18 | config.default_formatter = "doc" if config.files_to_run.one? 19 | 20 | config.order = :random 21 | Kernel.srand config.seed 22 | end 23 | 24 | Jekyll.logger.adjust_verbosity(:quiet => true) 25 | 26 | def fixture_path(fixture) 27 | File.expand_path "./fixtures/#{fixture}", File.dirname(__FILE__) 28 | end 29 | 30 | def fixture_site(fixture, override = {}) 31 | default_config = { "source" => fixture_path(fixture) } 32 | config = Jekyll::Utils.deep_merge_hashes(default_config, override) 33 | config = Jekyll.configuration(config) 34 | Jekyll::Site.new(config) 35 | end 36 | 37 | # Create a page, pass it to the block, delete the page 38 | def with_page(path, content: nil, site: nil) 39 | site ||= fixture_site("tmp") 40 | base = site.source 41 | 42 | dir = File.dirname(path).sub(%r!^\.$!, "") 43 | name = File.basename(path) 44 | full_path = File.join(base, dir, name) 45 | 46 | content ||= "# #{name}" 47 | FileUtils.mkdir_p File.join(base, dir) 48 | File.write(full_path, content) 49 | 50 | page = Jekyll::Page.new(site, base, dir, name) 51 | yield(page) 52 | File.delete(full_path) 53 | end 54 | 55 | RSpec::Matchers.define :be_an_existing_file do 56 | match { |path| File.exist?(path) } 57 | end 58 | --------------------------------------------------------------------------------