├── .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 ├── Gemfile ├── LICENSE.md ├── README.md ├── docs ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── SECURITY.md ├── jekyll-include-cache.gemspec ├── lib ├── jekyll-include-cache.rb └── jekyll-include-cache │ ├── cache.rb │ ├── tag.rb │ └── version.rb ├── script ├── bootstrap └── cibuild └── spec ├── fixtures └── site │ └── _includes │ └── foo.html ├── jekyll-include-tag ├── cache_spec.rb └── tag_spec.rb ├── jekyll-include-tag_spec.rb └── spec_helper.rb /.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 Include Cache. If you haven't already, please be sure to check out [the contributing guidelines](https://github.com/benbalter/jekyll-include-cache/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 Include Cache 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-include-cache/issues), especially those [labeled `help wanted`](https://github.com/benbalter/jekyll-include-cache/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.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: '33 14 * * 6' 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 | *.gem 3 | Gemfile.lock 4 | /tmp 5 | vendor/bundle 6 | .bundle 7 | .jekyll-cache 8 | -------------------------------------------------------------------------------- /.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 2021-09-16 19:19:04 UTC using RuboCop version 1.18.4. 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: Include. 11 | # Include: **/*.gemspec 12 | Gemspec/RequiredRubyVersion: 13 | Exclude: 14 | - 'jekyll-include-cache.gemspec' 15 | 16 | # Offense count: 4 17 | # Configuration parameters: Prefixes. 18 | # Prefixes: when, with, without 19 | RSpec/ContextWording: 20 | Exclude: 21 | - 'spec/jekyll-include-tag/cache_spec.rb' 22 | - 'spec/jekyll-include-tag/tag_spec.rb' 23 | - 'spec/jekyll-include-tag_spec.rb' 24 | 25 | # Offense count: 3 26 | # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. 27 | # Include: **/*_spec*rb*, **/spec/**/* 28 | RSpec/FilePath: 29 | Exclude: 30 | - 'spec/jekyll-include-tag/cache_spec.rb' 31 | - 'spec/jekyll-include-tag/tag_spec.rb' 32 | - 'spec/jekyll-include-tag_spec.rb' 33 | 34 | # Offense count: 6 35 | RSpec/MultipleExpectations: 36 | Max: 2 37 | 38 | # Offense count: 5 39 | # Configuration parameters: AllowSubject. 40 | RSpec/MultipleMemoizedHelpers: 41 | Max: 16 42 | 43 | # Offense count: 34 44 | # Configuration parameters: IgnoreSharedExamples. 45 | RSpec/NamedSubject: 46 | Exclude: 47 | - 'spec/jekyll-include-tag/cache_spec.rb' 48 | - 'spec/jekyll-include-tag/tag_spec.rb' 49 | - 'spec/jekyll-include-tag_spec.rb' 50 | 51 | # Offense count: 8 52 | # Cop supports --auto-correct. 53 | # Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers. 54 | # SupportedStyles: inflected, explicit 55 | RSpec/PredicateMatcher: 56 | Exclude: 57 | - 'spec/jekyll-include-tag/cache_spec.rb' 58 | - 'spec/jekyll-include-tag/tag_spec.rb' 59 | - 'spec/jekyll-include-tag_spec.rb' 60 | 61 | # Offense count: 2 62 | RSpec/ScatteredSetup: 63 | Exclude: 64 | - 'spec/jekyll-include-tag/tag_spec.rb' 65 | 66 | # Offense count: 1 67 | RSpec/SubjectStub: 68 | Exclude: 69 | - 'spec/jekyll-include-tag/tag_spec.rb' 70 | -------------------------------------------------------------------------------- /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 Include Cache 2 | 3 | *A Jekyll plugin to cache the rendering of Liquid includes* 4 | 5 | [![CI](https://github.com/benbalter/jekyll-include-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/benbalter/jekyll-include-cache/actions/workflows/ci.yml) 6 | 7 | ## What it does 8 | 9 | If you have a computationally expensive include (such as a sidebar or navigation), Jekyll Include Cache renders the include once, and then reuses the output any time that includes is called with the same arguments, potentially speeding up your site's build significantly. 10 | 11 | ## Usage 12 | 13 | 1. Add the following to your site's Gemfile: 14 | 15 | ```ruby 16 | gem 'jekyll-include-cache' 17 | ``` 18 | 19 | 2. Add the following to your site's config file: 20 | 21 | ```yml 22 | plugins: 23 | - jekyll-include-cache 24 | ``` 25 | 💡 If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`. 26 | 27 | 3. Replace `{% include foo.html %}` in your template with `{% include_cached foo.html %}` 28 | 29 | ## One potential gotcha 30 | 31 | For Jekyll Include Cache to work, you cannot rely on the page context to pass variables to your include (e.g., `assign foo=bar` or `page.title`). Instead, you must explicitly pass all variables to the include as arguments, and reference them within the include as `include.foo` (instead of `page.foo` or just `foo`). 32 | 33 | ### Good 34 | 35 | In your template: 36 | 37 | ```liquid 38 | {% include_cached shirt.html size=medium color=red %} 39 | ``` 40 | 41 | In your include: 42 | 43 | ```liquid 44 | Buy our {{ include.color }} shirt in {{ include.size }}! 45 | ``` 46 | 47 | ### Bad 48 | 49 | In your template: 50 | 51 | ```liquid 52 | {% assign color=blue %} 53 | {% include_cached shirt.html %} 54 | ``` 55 | 56 | In your include: 57 | 58 | ```liquid 59 | Buy our {{ color }} shirt in {{ page.size }}! 60 | ``` 61 | -------------------------------------------------------------------------------- /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 Include Cache 2 | 3 | Hi there! We're thrilled that you'd like to contribute to Jekyll Include Cache. Your help is essential for keeping it great. 4 | 5 | Jekyll Include Cache 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 Include Cache 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-include-cache/issues) to see if your bug has already been reported. If it hasn't please [submit a new issue](https://github.com/benbalter/jekyll-include-cache/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 Include Cache, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Jekyll Include Cache 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-include-cache/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 Include Cache? You can start by looking through these "good first issue" and "help wanted" issues: 40 | 41 | * [Good first issues](https://github.com/benbalter/jekyll-include-cache/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-include-cache/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-include-cache/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-include-cache/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-include-cache.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.unshift File.expand_path("lib", __dir__) 4 | require "jekyll-include-cache/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "jekyll-include-cache" 8 | s.version = JekyllIncludeCache::VERSION 9 | s.authors = ["Ben Balter"] 10 | s.email = ["ben.balter@github.com"] 11 | s.homepage = "https://github.com/benbalter/jekyll-include-cache" 12 | s.summary = "A Jekyll plugin to cache the rendering of Liquid includes" 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_dependency "jekyll", ">= 3.7", "< 5.0" 20 | s.add_development_dependency "rspec", "~> 3.5" 21 | s.add_development_dependency "rubocop", "~> 1.0" 22 | s.add_development_dependency "rubocop-jekyll", "~> 0.3" 23 | s.add_development_dependency "rubocop-performance", "~> 1.5" 24 | s.add_development_dependency "rubocop-rspec", "~> 2.0" 25 | end 26 | -------------------------------------------------------------------------------- /lib/jekyll-include-cache.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll" 4 | 5 | module JekyllIncludeCache 6 | autoload :Tag, "jekyll-include-cache/tag" 7 | autoload :Cache, "jekyll-include-cache/cache" 8 | 9 | class << self 10 | def cache 11 | @cache ||= if defined? Jekyll::Cache 12 | Jekyll::Cache.new(self.class.name) 13 | else 14 | JekyllIncludeCache::Cache.new 15 | end 16 | end 17 | 18 | def reset 19 | JekyllIncludeCache.cache.clear 20 | end 21 | end 22 | end 23 | 24 | Liquid::Template.register_tag("include_cached", JekyllIncludeCache::Tag) 25 | Jekyll::Hooks.register :site, :pre_render do |_site| 26 | JekyllIncludeCache.reset 27 | end 28 | -------------------------------------------------------------------------------- /lib/jekyll-include-cache/cache.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Jekyll 4.x comptable caching class for pre-4.x compatibility 4 | module JekyllIncludeCache 5 | class Cache 6 | extend Forwardable 7 | 8 | def_delegators :@cache, :[]=, :key?, :delete, :clear 9 | 10 | def initialize(_name = nil) 11 | @cache = {} 12 | end 13 | 14 | def getset(key) 15 | if key?(key) 16 | @cache[key] 17 | else 18 | value = yield 19 | @cache[key] = value 20 | value 21 | end 22 | end 23 | 24 | def [](key) 25 | if key?(key) 26 | @cache[key] 27 | else 28 | raise 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/jekyll-include-cache/tag.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "digest/md5" 4 | 5 | module JekyllIncludeCache 6 | class Tag < Jekyll::Tags::IncludeTag 7 | def self.digest_cache 8 | @digest_cache ||= {} 9 | end 10 | 11 | def render(context) 12 | path = path(context) 13 | params = parse_params(context) if @params 14 | key = key(path, params) 15 | return unless path 16 | 17 | if JekyllIncludeCache.cache.key?(key) 18 | Jekyll.logger.debug "Include cache hit:", path 19 | JekyllIncludeCache.cache[key] 20 | else 21 | Jekyll.logger.debug "Include cache miss:", path 22 | JekyllIncludeCache.cache[key] = super 23 | end 24 | end 25 | 26 | private 27 | 28 | def path(context) 29 | site = context.registers[:site] 30 | file = render_variable(context) || @file 31 | locate_include_file(context, file, site.safe) 32 | end 33 | 34 | def key(path, params) 35 | path_hash = path.hash 36 | params_hash = quick_hash(params) 37 | self.class.digest_cache[path_hash] ||= {} 38 | self.class.digest_cache[path_hash][params_hash] ||= digest(path_hash, params_hash) 39 | end 40 | 41 | def quick_hash(params) 42 | return params.hash unless params 43 | 44 | md5 = Digest::MD5.new 45 | 46 | params.sort.each do |_, value| 47 | # Using the fact that Jekyll documents don't change during a build. 48 | # Instead of calculating the hash of an entire document (expensive!) 49 | # we just use its object id. 50 | if value.is_a? Jekyll::Drops::Drop 51 | md5.update value.object_id.to_s 52 | else 53 | md5.update value.hash.to_s 54 | end 55 | end 56 | 57 | md5.hexdigest 58 | end 59 | 60 | def digest(path_hash, params_hash) 61 | md5 = Digest::MD5.new 62 | md5.update path_hash.to_s 63 | md5.update params_hash.to_s 64 | md5.hexdigest 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /lib/jekyll-include-cache/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module JekyllIncludeCache 4 | VERSION = "0.2.1" 5 | end 6 | -------------------------------------------------------------------------------- /script/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | bundle install 4 | -------------------------------------------------------------------------------- /script/cibuild: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | bundle exec rspec 6 | bundle exec rubocop -S -D 7 | gem build jekyll-include-cache.gemspec 8 | -------------------------------------------------------------------------------- /spec/fixtures/site/_includes/foo.html: -------------------------------------------------------------------------------- 1 | Some content 2 | -------------------------------------------------------------------------------- /spec/jekyll-include-tag/cache_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe JekyllIncludeCache::Cache do 4 | before { subject["foo"] = "bar" } 5 | 6 | it "sets" do 7 | subject["foo2"] = "bar2" 8 | cache = subject.instance_variable_get("@cache") 9 | expect(cache["foo2"]).to eql("bar2") 10 | end 11 | 12 | it "gets" do 13 | expect(subject["foo"]).to eql("bar") 14 | end 15 | 16 | it "raises when a key doesn't exist" do 17 | expect { subject["doesnt_exist"] }.to raise_error(RuntimeError) 18 | end 19 | 20 | it "knows if a key exists" do 21 | expect(subject.key?("foo")).to be_truthy 22 | expect(subject.key?("bar")).to be_falsy 23 | end 24 | 25 | it "deletes" do 26 | subject["foo2"] = "bar2" 27 | expect(subject.key?("foo2")).to be_truthy 28 | subject.delete("foo2") 29 | expect(subject.key?("foo2")).to be_falsy 30 | end 31 | 32 | it "clears" do 33 | expect(subject.key?("foo")).to be_truthy 34 | subject.clear 35 | cache = subject.instance_variable_get("@cache") 36 | expect(cache).to eql({}) 37 | end 38 | 39 | context "getset" do 40 | it "returns an existing value" do 41 | value = subject.getset "foo" do 42 | "bar2" 43 | end 44 | 45 | expect(value).to eql("bar") 46 | end 47 | 48 | it "sets a new value" do 49 | value = subject.getset "foo3" do 50 | "bar3" 51 | end 52 | 53 | expect(value).to eql("bar3") 54 | expect(subject["foo3"]).to eql("bar3") 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/jekyll-include-tag/tag_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe JekyllIncludeCache::Tag do 4 | subject { described_class.send(:new, tag_name, markup, parse_context) } 5 | 6 | let(:tag_name) { "include_cached" } 7 | let(:cache) { JekyllIncludeCache.cache } 8 | let(:path) { subject.send(:path, context) } 9 | let(:parsed_params) { subject.parse_params(context) } 10 | let(:cache_key) { subject.send(:key, path, parsed_params) } 11 | let(:file_path) { "foo.html" } 12 | let(:params) { "foo=bar foo2=bar2" } 13 | let(:markup) { "#{file_path} #{params}" } 14 | 15 | let(:overrides) { {} } 16 | let(:site) { fixture_site("site", overrides) } 17 | let(:environments) { {} } 18 | let(:outer_scope) { {} } 19 | let(:registers) { { :site => site } } 20 | let(:context) { Liquid::Context.new(environments, outer_scope, registers) } 21 | let(:parse_context) { Liquid::ParseContext.new } 22 | 23 | it "determines the path" do 24 | expected = File.expand_path "../fixtures/site/_includes/foo.html", __dir__ 25 | expect(path).to eql(expected) 26 | end 27 | 28 | context "building the key" do 29 | it "builds the key" do 30 | key = subject.send(:key, "foo.html", "foo" => "bar", "foo2" => "bar2") 31 | params = { "foo" => "bar", "foo2" => "bar2" } 32 | expect(key).to eql( 33 | subject.send(:digest, "foo.html".hash, subject.send(:quick_hash, params)) 34 | ) 35 | end 36 | 37 | it "builds the key based on the path" do 38 | key = subject.send(:key, "foo2.html", "foo" => "bar", "foo2" => "bar2") 39 | params = { "foo" => "bar", "foo2" => "bar2" } 40 | expect(key).to eql( 41 | subject.send(:digest, "foo2.html".hash, subject.send(:quick_hash, params)) 42 | ) 43 | end 44 | 45 | it "builds the key based on the params" do 46 | key = subject.send(:key, "foo2.html", "foo" => "bar") 47 | params = { "foo" => "bar" } 48 | expect(key).to eql(subject.send(:digest, "foo2.html".hash, subject.send(:quick_hash, params))) 49 | end 50 | end 51 | 52 | context "rendering" do 53 | before { subject.render(context) } 54 | 55 | let(:rendered) { subject.render(context) } 56 | 57 | it "renders" do 58 | expect(rendered).to eql("Some content\n") 59 | end 60 | 61 | it "caches the include" do 62 | expect(cache.key?(cache_key)).to be_truthy 63 | expect(cache[cache_key]).to eql("Some content\n") 64 | end 65 | 66 | context "with the cache stubbed" do 67 | before { allow(subject).to receive(:key).and_return(cache_key) } 68 | 69 | before { cache[cache_key] = "Some other content\n" } 70 | 71 | let(:cache_key) { "asdf" } 72 | 73 | it "returns the cached value" do 74 | expect(rendered).to eql("Some other content\n") 75 | end 76 | end 77 | end 78 | 79 | context "with an invalid include" do 80 | let(:file_path) { "foo2.html" } 81 | 82 | it "raises an error" do 83 | expect { subject.render(context) }.to raise_error(IOError) 84 | end 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /spec/jekyll-include-tag_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe JekyllIncludeCache do 4 | subject { described_class.cache } 5 | 6 | context "with an empty cache" do 7 | it "initializess the cache" do 8 | expect(described_class.cache).to respond_to(:[]) 9 | expect(described_class.cache).to respond_to(:[]=) 10 | end 11 | end 12 | 13 | context "with something cached" do 14 | before { subject["foo"] = "bar" } 15 | 16 | it "caches" do 17 | expect(subject.key?("foo")).to be_truthy 18 | end 19 | 20 | it "returns the cache" do 21 | expect(subject["foo"]).to eql("bar") 22 | end 23 | end 24 | 25 | context "clearing the cache on render" do 26 | let(:site) { fixture_site("site") } 27 | 28 | before do 29 | subject["foo"] = "bar" 30 | Jekyll::Hooks.trigger :site, :pre_render, site, site.site_payload 31 | end 32 | 33 | it "clears the cache" do 34 | expect(subject.key?("foo")).not_to be_truthy 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll-include-cache" 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 | Jekyll.logger.adjust_verbosity(:quiet => true) 23 | 24 | Jekyll::Cache.cache_dir = File.expand_path("../tmp", __dir__) if defined? Jekyll::Cache 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 | --------------------------------------------------------------------------------