├── .bundle └── config ├── .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.rubocop.yml │ ├── ci.yml │ └── codeql-analysis.yml ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .rubocop_todo.yml ├── Gemfile ├── LICENSE ├── README.md ├── docs ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── SECURITY.md ├── jekyll-default-layout.gemspec ├── lib ├── jekyll-default-layout.rb └── jekyll-default-layout │ ├── generator.rb │ └── version.rb ├── script ├── bootstrap └── cibuild └── spec ├── fixtures └── site │ ├── _collection_test │ └── document.md │ ├── _config.yml │ ├── _layouts │ ├── collection_test.html │ ├── default.html │ ├── home.html │ ├── page.html │ └── post.html │ ├── _posts │ └── 2016-01-01-post.md │ ├── file.html │ ├── index.md │ ├── page-with-layout.md │ ├── page.md │ └── with-defaults │ └── page-with-defaults.md ├── jekyll-default-layout └── generator_spec.rb └── spec_helper.rb /.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_PATH: "vendor/bundle" 3 | -------------------------------------------------------------------------------- /.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 Default Layout. If you haven't already, please be sure to check out [the contributing guidelines](https://github.com/benbalter/jekyll-default-layout/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 Default Layout 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-default-layout/issues), especially those [labeled `help wanted`](https://github.com/benbalter/jekyll-default-layout/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)." 21 | 22 | # Bug workaround 23 | contact_links: [] 24 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: bundler 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "10:00" 8 | timezone: US/Eastern 9 | open-pull-requests-limit: 99 10 | -------------------------------------------------------------------------------- /.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.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: ../../.rubocop.yml 2 | 3 | # Disable problematic cops with incompatible configurations 4 | FactoryBot/CreateList: 5 | Enabled: false 6 | RSpecRails/NegationBeValid: 7 | Enabled: false -------------------------------------------------------------------------------- /.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: '19 20 * * 2' 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 | spec/fixtures/site/_site 3 | *.gem 4 | Gemfile.lock 5 | spec/fixtures/site/.jekyll-cache/ 6 | vendor/ 7 | .bundle/ -------------------------------------------------------------------------------- /.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 | 7 | inherit_gem: 8 | rubocop-jekyll: .rubocop.yml 9 | 10 | AllCops: 11 | Exclude: 12 | - vendor/**/* 13 | NewCops: enable 14 | 15 | Metrics/BlockLength: 16 | Exclude: 17 | - spec/**/* 18 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config` 3 | # on 2025-05-22 22:39:48 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-default-layout.gemspec' 15 | 16 | # Offense count: 1 17 | # This cop supports safe autocorrection (--autocorrect). 18 | Lint/RedundantCopDisableDirective: 19 | Exclude: 20 | - 'lib/jekyll-default-layout/generator.rb' 21 | -------------------------------------------------------------------------------- /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 | 9 | # Pin specific versions to avoid compatibility issues 10 | gem "rubocop-factory_bot", "= 2.24.0" 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-present Ben Balter and jekyll-default-layout contributors 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 Default Layout 2 | 3 | *Silently sets default layouts for Jekyll pages and posts* 4 | 5 | [![CI](https://github.com/benbalter/jekyll-default-layout/actions/workflows/ci.yml/badge.svg)](https://github.com/benbalter/jekyll-default-layout/actions/workflows/ci.yml) 6 | 7 | ## Usage 8 | 9 | 1. Add the following to your site's Gemfile: 10 | 11 | ```ruby 12 | gem 'jekyll-default-layout' 13 | ``` 14 | 15 | 2. And the following to your site's `_config.yml`: 16 | 17 | ```yml 18 | plugins: 19 | - jekyll-default-layout 20 | ``` 21 | 22 | Note: If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`. 23 | 24 | ## What it does 25 | 26 | If no layout is specified for a Markdown post or page, the plugin automatically sets the "home", "post", "page", or "default" layout if it exists. 27 | 28 | What layout is used: 29 | 30 | * `/index.md` - the home layout, the page layout, or the default layout, if they exist, in that order 31 | * A page - the page layout or the default layout, if they exist, in that order 32 | * A post - the post layout or the default layout, if they exist, in that order 33 | * A collection document - a layout matching the collection name or the default layout, if they exist, in that order 34 | 35 | ## Disabling 36 | 37 | For a specific post or page, add `layout: null` to the front matter. 38 | -------------------------------------------------------------------------------- /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 Default Layout 2 | 3 | Hi there! We're thrilled that you'd like to contribute to Jekyll Default Layout. Your help is essential for keeping it great. 4 | 5 | Jekyll Default Layout 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 Default Layout 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-default-layout/issues) to see if your bug has already been reported. If it hasn't please [submit a new issue](https://github.com/benbalter/jekyll-default-layout/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 Default Layout, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Jekyll Default Layout 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-default-layout/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 Default Layout? You can start by looking through these "good first issue" and "help wanted" issues: 40 | 41 | * [Good first issues](https://github.com/benbalter/jekyll-default-layout/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-default-layout/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-default-layout/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-default-layout/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-default-layout.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.unshift File.expand_path("lib", __dir__) 4 | require "jekyll-default-layout/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "jekyll-default-layout" 8 | s.version = JekyllDefaultLayout::VERSION 9 | s.authors = ["Ben Balter"] 10 | s.email = ["ben.balter@github.com"] 11 | s.homepage = "https://github.com/benbalter/jekyll-default-layout" 12 | s.summary = "Silently sets default layouts for Jekyll pages and posts" 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 | 19 | s.add_runtime_dependency "jekyll", ">= 3.0", "< 5.0" 20 | s.add_development_dependency "kramdown-parser-gfm", "~> 1.0" 21 | s.add_development_dependency "rspec", "~> 3.5" 22 | s.add_development_dependency "rubocop", "~> 1.0" 23 | s.add_development_dependency "rubocop-factory_bot", "~> 2.22.0" 24 | s.add_development_dependency "rubocop-jekyll", "~> 0.11" 25 | s.add_development_dependency "rubocop-performance", "~> 1.6" 26 | s.add_development_dependency "rubocop-rspec", "~> 3.0" 27 | end 28 | -------------------------------------------------------------------------------- /lib/jekyll-default-layout.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll" 4 | require "jekyll-default-layout/generator" 5 | 6 | module JekyllDefaultLayout 7 | end 8 | -------------------------------------------------------------------------------- /lib/jekyll-default-layout/generator.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module JekyllDefaultLayout 4 | # Injects front matter defaults to set default layouts, if they exist 5 | class Generator < Jekyll::Generator 6 | attr_accessor :site 7 | 8 | safe true 9 | priority :lowest 10 | 11 | def initialize(site) 12 | @site = site 13 | end 14 | 15 | def generate(site) 16 | @site = site 17 | documents.each do |document| 18 | next unless should_set_layout?(document) 19 | 20 | document.data["layout"] = layout_for(document) 21 | end 22 | end 23 | 24 | def should_set_layout?(document) 25 | markdown?(document) && !layout_specified?(document) 26 | end 27 | 28 | # Does the given layout exist for the site? 29 | def layout_exists?(layout) 30 | !site.layouts[layout].nil? 31 | end 32 | 33 | # Has the user already specified a default for this layout? 34 | # Note: We must use `to_liquid`, and not data, to ensure front matter defaults 35 | def layout_specified?(document) 36 | document.to_liquid.key? "layout" 37 | end 38 | 39 | def markdown?(document) 40 | markdown_converter.matches(document.extname) 41 | end 42 | 43 | # What layout is appropriate for this document, if any 44 | # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity 45 | def layout_for(document) 46 | if index?(document) && layout_exists?("home") 47 | "home" 48 | elsif page?(document) && layout_exists?("page") 49 | "page" 50 | elsif post?(document) && layout_exists?("post") 51 | "post" 52 | elsif collection?(document) && layout_exists?(document.collection.label) 53 | document.collection.label 54 | elsif layout_exists?("default") 55 | "default" 56 | end 57 | end 58 | # rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity 59 | 60 | def documents 61 | [site.pages, site.collections.values.map(&:docs)].flatten 62 | end 63 | 64 | def markdown_converter 65 | @markdown_converter ||= site.find_converter_instance(Jekyll::Converters::Markdown) 66 | end 67 | 68 | def post?(document) 69 | document.is_a?(Jekyll::Document) && document.collection.label == "posts" 70 | end 71 | 72 | def page?(document) 73 | document.is_a?(Jekyll::Page) 74 | end 75 | 76 | def collection?(document) 77 | document.is_a?(Jekyll::Document) && !post?(document) 78 | end 79 | 80 | def index?(document) 81 | document.url == "/" 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /lib/jekyll-default-layout/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module JekyllDefaultLayout 4 | VERSION = "0.1.5" 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-default-layout.gemspec 8 | -------------------------------------------------------------------------------- /spec/fixtures/site/_collection_test/document.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Collection test document 3 | --- 4 | 5 | This is a test document in a collection. -------------------------------------------------------------------------------- /spec/fixtures/site/_config.yml: -------------------------------------------------------------------------------- 1 | collections: 2 | collection_test: 3 | output: true -------------------------------------------------------------------------------- /spec/fixtures/site/_layouts/collection_test.html: -------------------------------------------------------------------------------- 1 | COLLECTION_TEST LAYOUT 2 | {{ content }} -------------------------------------------------------------------------------- /spec/fixtures/site/_layouts/default.html: -------------------------------------------------------------------------------- 1 | DEFAULT LAYOUT 2 | 3 | {{ content }} 4 | -------------------------------------------------------------------------------- /spec/fixtures/site/_layouts/home.html: -------------------------------------------------------------------------------- 1 | HOME LAYOUT 2 | 3 | {{ content }} 4 | -------------------------------------------------------------------------------- /spec/fixtures/site/_layouts/page.html: -------------------------------------------------------------------------------- 1 | PAGE LAYOUT 2 | 3 | {{ content }} 4 | -------------------------------------------------------------------------------- /spec/fixtures/site/_layouts/post.html: -------------------------------------------------------------------------------- 1 | POST LAYOUT 2 | 3 | {{ content }} 4 | -------------------------------------------------------------------------------- /spec/fixtures/site/_posts/2016-01-01-post.md: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | # Post 5 | -------------------------------------------------------------------------------- /spec/fixtures/site/file.html: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 |

HTML file

5 | -------------------------------------------------------------------------------- /spec/fixtures/site/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | # The index 5 | -------------------------------------------------------------------------------- /spec/fixtures/site/page-with-layout.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: foo 3 | --- 4 | -------------------------------------------------------------------------------- /spec/fixtures/site/page.md: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | # Page 5 | -------------------------------------------------------------------------------- /spec/fixtures/site/with-defaults/page-with-defaults.md: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | # Page with defaults 5 | -------------------------------------------------------------------------------- /spec/jekyll-default-layout/generator_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe JekyllDefaultLayout::Generator do 4 | let(:overrides) { {} } 5 | let(:site) { fixture_site("site", overrides) } 6 | let(:subject) { described_class.new(site) } 7 | let(:page) { page_by_path(site, "page.md") } 8 | let(:index) { page_by_path(site, "index.md") } 9 | let(:page_with_layout) { page_by_path(site, "page-with-layout.md") } 10 | let(:page_with_defaults) do 11 | page_by_path(site, "with-defaults/page-with-defaults.md") 12 | end 13 | let(:html_file) { page_by_path(site, "file.html") } 14 | let(:post) { site.posts.docs.first } 15 | let(:collection_doc) { site.collections["collection_test"].docs.first } 16 | 17 | before do 18 | site.reset 19 | site.read 20 | end 21 | 22 | it "knows a page is a page" do 23 | expect(subject.page?(page)).to be(true) 24 | expect(subject.page?(post)).to be(false) 25 | end 26 | 27 | it "knows a post is a post" do 28 | expect(subject.post?(post)).to be(true) 29 | expect(subject.post?(page)).to be(false) 30 | expect(subject.post?(collection_doc)).to be(false) 31 | end 32 | 33 | it "knows a collection document is a collection" do 34 | expect(subject.collection?(collection_doc)).to be(true) 35 | expect(subject.collection?(post)).to be(false) 36 | expect(subject.collection?(page)).to be(false) 37 | end 38 | 39 | it "knows the index is the index" do 40 | expect(subject.index?(index)).to be(true) 41 | expect(subject.index?(post)).to be(false) 42 | expect(subject.index?(page)).to be(false) 43 | end 44 | 45 | it "grabs the markdown converter" do 46 | expect(subject.markdown_converter).to be_a(Jekyll::Converters::Markdown) 47 | end 48 | 49 | it "grabs the documents" do 50 | expect(subject.documents.count).to be > 6 51 | end 52 | 53 | it "knows a file is a markdown file" do 54 | expect(subject.markdown?(page)).to be(true) 55 | expect(subject.markdown?(html_file)).to be(false) 56 | end 57 | 58 | it "knows when a layout's been specified" do 59 | expect(subject.layout_specified?(page)).to be(false) 60 | expect(subject.layout_specified?(page_with_layout)).to be(true) 61 | end 62 | 63 | it "knows when a layout exists" do 64 | expect(subject.layout_exists?("page")).to be(true) 65 | expect(subject.layout_exists?("foo")).to be(false) 66 | end 67 | 68 | context "determining layouts" do 69 | it "knows the layout for a post" do 70 | expect(subject.layout_for(post)).to eql("post") 71 | end 72 | 73 | it "knows the layout for a page" do 74 | expect(subject.layout_for(page)).to eql("page") 75 | end 76 | 77 | it "knows the layout for the index" do 78 | expect(subject.layout_for(index)).to eql("home") 79 | end 80 | 81 | it "knows the layout for a collection document" do 82 | expect(subject.layout_for(collection_doc)).to eql("collection_test") 83 | end 84 | 85 | context "without the page layout" do 86 | before { site.layouts.delete("page") } 87 | 88 | context "without the collection layout" do 89 | before { site.layouts.delete("collection_test") } 90 | 91 | it "knows the layout for a collection document" do 92 | expect(subject.layout_for(collection_doc)).to eql("default") 93 | end 94 | end 95 | it "knows the layout for a page" do 96 | expect(subject.layout_for(page)).to eql("default") 97 | end 98 | end 99 | 100 | context "without the post layout" do 101 | before { site.layouts.delete("post") } 102 | 103 | it "knows the layout for a post" do 104 | expect(subject.layout_for(post)).to eql("default") 105 | end 106 | end 107 | 108 | context "without the home layout" do 109 | before { site.layouts.delete("home") } 110 | 111 | it "knows the layout for the index" do 112 | expect(subject.layout_for(index)).to eql("page") 113 | end 114 | 115 | context "without the page layout" do 116 | before { site.layouts.delete("page") } 117 | 118 | it "knows the layout for the index" do 119 | expect(subject.layout_for(index)).to eql("default") 120 | end 121 | end 122 | end 123 | 124 | context "without any layouts" do 125 | before do 126 | site.layouts.delete("post") 127 | site.layouts.delete("page") 128 | site.layouts.delete("default") 129 | site.layouts.delete("home") 130 | end 131 | 132 | it "knows the layout for a post" do 133 | expect(subject.layout_for(post)).to be_nil 134 | end 135 | 136 | it "knows the layout for a page" do 137 | expect(subject.layout_for(page)).to be_nil 138 | end 139 | 140 | it "knows the layout for the index" do 141 | expect(subject.layout_for(index)).to be_nil 142 | end 143 | end 144 | end 145 | 146 | context "when to set the layout" do 147 | it "knows to set the layout for markdown files" do 148 | expect(subject.should_set_layout?(page)).to be(true) 149 | end 150 | 151 | it "knows not to set the layout for html files" do 152 | expect(subject.should_set_layout?(html_file)).to be(false) 153 | end 154 | 155 | it "knows not to set the layout for files with layouts" do 156 | expect(subject.should_set_layout?(page_with_layout)).to be(false) 157 | end 158 | end 159 | 160 | context "generating" do 161 | before { site.process } 162 | 163 | it "sets the layout for pages" do 164 | expect(page.to_liquid["layout"]).to eql("page") 165 | end 166 | 167 | it "sets the layout for posts" do 168 | expect(post.to_liquid["layout"]).to eql("post") 169 | end 170 | 171 | it "sets the layout for the index" do 172 | expect(index.to_liquid["layout"]).to eql("home") 173 | end 174 | 175 | it "sets the layout for collection documents" do 176 | expect(collection_doc.to_liquid["layout"]).to eql("collection_test") 177 | end 178 | 179 | it "doesn't set the layout for HTML files" do 180 | expect(html_file.to_liquid["layout"]).to be_nil 181 | end 182 | 183 | it "doesn't clobber existing layout preferences" do 184 | expect(page_with_layout.to_liquid["layout"]).to eql("foo") 185 | end 186 | 187 | context "rendering" do 188 | it "renders pages with the layout" do 189 | expect(content_of_file("page.html")).to match("PAGE LAYOUT") 190 | end 191 | 192 | it "renders posts with the layout" do 193 | expect(content_of_file("2016/01/01/post.html")).to match("POST LAYOUT") 194 | end 195 | 196 | it "renders the index with the layout" do 197 | expect(content_of_file("index.html")).to match("HOME LAYOUT") 198 | end 199 | 200 | it "renders collection documents with the layout" do 201 | expect(content_of_file("collection_test/document.html")).to match("COLLECTION_TEST LAYOUT") 202 | end 203 | 204 | it "doesn't mangle HTML files" do 205 | expect(content_of_file("file.html")).not_to match("LAYOUT") 206 | end 207 | 208 | context "with front matter defaults" do 209 | let(:layout) { "config-specified-layout.html" } 210 | let(:defaults) do 211 | [ 212 | { 213 | "scope" => { "path" => "with-defaults" }, 214 | "values" => { "layout" => layout }, 215 | }, 216 | ] 217 | end 218 | let(:overrides) { { "defaults" => defaults } } 219 | 220 | before { site.process } 221 | 222 | it "respects front matter defaults" do 223 | expect(page_with_defaults.to_liquid["layout"]).to eql(layout) 224 | end 225 | end 226 | end 227 | end 228 | end 229 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll-default-layout" 4 | 5 | RSpec.configure do |config| 6 | config.expect_with :rspec do |expectations| 7 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 8 | end 9 | 10 | config.mock_with :rspec do |mocks| 11 | mocks.verify_partial_doubles = true 12 | end 13 | 14 | config.filter_run_when_matching :focus 15 | config.example_status_persistence_file_path = "spec/examples.txt" 16 | config.disable_monkey_patching! 17 | config.default_formatter = "doc" if config.files_to_run.one? 18 | config.order = :random 19 | Kernel.srand config.seed 20 | end 21 | 22 | def fixture_path(fixture) 23 | File.expand_path "./fixtures/#{fixture}", File.dirname(__FILE__) 24 | end 25 | 26 | def fixture_site(fixture, override = {}) 27 | default_config = { 28 | "source" => fixture_path(fixture), 29 | "destination" => fixture_path("#{fixture}/_site"), 30 | "quiet" => true, 31 | } 32 | config = Jekyll::Utils.deep_merge_hashes(default_config, override) 33 | config = Jekyll.configuration(config) 34 | Jekyll::Site.new(config) 35 | end 36 | 37 | def page_by_path(site, path) 38 | site.pages.find { |p| p.path == path } 39 | end 40 | 41 | def content_of_file(path) 42 | File.read(File.join(fixture_path("site"), "_site", path)) 43 | end 44 | --------------------------------------------------------------------------------