├── .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 │ └── codeql-analysis.yml ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .rubocop_todo.yml ├── .travis.yml ├── Gemfile ├── LICENSE.md ├── README.md ├── docs ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── SECURITY.md ├── jekyll-readme-index.gemspec ├── lib ├── jekyll-readme-index.rb ├── jekyll-readme-index │ ├── generator.rb │ └── version.rb └── jekyll │ └── static_file_ext.rb ├── script ├── bootstrap └── cibuild └── spec ├── fixtures ├── index-no-readme │ └── index.html ├── no-readme-no-index │ └── foo.md ├── readme-and-html-index │ ├── index.html │ └── readme.markdown ├── readme-and-html-page-index │ ├── index.html │ └── readme.markdown ├── readme-and-index-permalink │ ├── index.md │ └── readme.markdown ├── readme-and-index │ ├── index.md │ └── readme.markdown ├── readme-and-nested-readme │ ├── README.md │ ├── other.md │ ├── with_readme │ │ ├── README.md │ │ └── other.md │ ├── with_readme_and_index │ │ ├── README.md │ │ └── index.html │ └── without_readme │ │ └── other.md ├── readme-no-index │ └── README.md ├── readme-with-frontmatter │ └── README.md ├── xhtml-index │ └── index.md └── xml-index │ └── index.xml ├── jekyll-readme-index └── generator_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 Readme Index. If you haven't already, please be sure to check out [the contributing guidelines](https://github.com/benbalter/jekyll-readme-index/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 Readme Index 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-readme-index/issues), especially those [labeled `help wanted`](https://github.com/benbalter/jekyll-readme-index/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/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: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '25 22 * * 0' 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 | .ruby* 6 | spec/fixtures/**/.jekyll-cache -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: .rubocop_todo.yml 2 | 3 | require: 4 | - rubocop-performance 5 | - rubocop-rspec 6 | - rubocop-jekyll 7 | 8 | inherit_gem: 9 | rubocop-jekyll: .rubocop.yml 10 | 11 | AllCops: 12 | Exclude: 13 | - vendor/**/* 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 2019-10-30 13:02:41 -0400 using RuboCop version 0.71.0. 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: 7 10 | # Configuration parameters: Prefixes. 11 | # Prefixes: when, with, without 12 | RSpec/ContextWording: 13 | Exclude: 14 | - "spec/jekyll-readme-index/generator_spec.rb" 15 | 16 | # Offense count: 1 17 | # Configuration parameters: CustomTransform, IgnoreMethods. 18 | RSpec/FilePath: 19 | Exclude: 20 | - "spec/jekyll-readme-index/generator_spec.rb" 21 | 22 | # Offense count: 18 23 | # Configuration parameters: AggregateFailuresByDefault. 24 | RSpec/MultipleExpectations: 25 | Max: 3 26 | 27 | # Offense count: 26 28 | # Configuration parameters: IgnoreSharedExamples. 29 | RSpec/NamedSubject: 30 | Exclude: 31 | - "spec/jekyll-readme-index/generator_spec.rb" 32 | 33 | # Offense count: 20 34 | RSpec/NestedGroups: 35 | Max: 4 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | rvm: 2.5 2 | before_install: gem install bundler 3 | language: ruby 4 | script: script/cibuild 5 | sudo: false 6 | cache: bundler 7 | 8 | env: 9 | - JEKYLL_VERSION="~> 3.0" 10 | - JEKYLL_VERSION="~> 4.0" 11 | -------------------------------------------------------------------------------- /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 Readme Index 2 | 3 | A Jekyll plugin to render a project's README as the site's index. 4 | 5 | [![Build Status](https://travis-ci.org/benbalter/jekyll-readme-index.svg?branch=master)](https://travis-ci.org/benbalter/jekyll-readme-index) 6 | 7 | ## What it does 8 | 9 | Let's say you have a GitHub repository with a `README.md` file, that you'd like to use as the index (main page) for a GitHub Pages site. You could rename the file to `index.md`, but then it wouldn't render on GitHub.com. You could add YAML front matter with `permalink: /` to the README, but why force a human to do what Jekyll can automate? 10 | 11 | If you have a readme file, and your site doesn't otherwise have an index file, this plugin instructs Jekyll to use the readme as the site's index. That's it. No more, no less. 12 | 13 | ## Usage 14 | 15 | 1. Add the following to your Gemfile 16 | 17 | ```ruby 18 | gem "jekyll-readme-index" 19 | ``` 20 | 21 | 2. Add the follow to your site's config 22 | 23 | ```yml 24 | plugins: 25 | - jekyll-readme-index 26 | ``` 27 | Note: If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`. 28 | 29 | ## Configuration 30 | 31 | Configuration options are optional are placed in `_config.yml` under the `readme_index` key. They default to: 32 | 33 | ```yml 34 | readme_index: 35 | enabled: true 36 | remove_originals: false 37 | with_frontmatter: false 38 | ``` 39 | 40 | ### Removing originals 41 | 42 | By default the original README markdown files will be included as static pages in the output. To remove them from the output, set the `remove_originals` key to `true`. 43 | 44 | ### Disabling 45 | 46 | Even if the plugin is enabled (e.g., via the `:jekyll_plugins` group in your Gemfile) you can disable it by setting the `enabled` key to `false`. 47 | -------------------------------------------------------------------------------- /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 Readme Index 2 | 3 | Hi there! We're thrilled that you'd like to contribute to Jekyll Readme Index. Your help is essential for keeping it great. 4 | 5 | Jekyll Readme Index 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 Readme Index 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-readme-index/issues) to see if your bug has already been reported. If it hasn't please [submit a new issue](https://github.com/benbalter/jekyll-readme-index/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 Readme Index, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Jekyll Readme Index 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-readme-index/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 Readme Index? You can start by looking through these "good first issue" and "help wanted" issues: 40 | 41 | * [Good first issues](https://github.com/benbalter/jekyll-readme-index/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-readme-index/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-readme-index/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-readme-index/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-readme-index.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.unshift File.expand_path("lib", __dir__) 4 | require "jekyll-readme-index/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "jekyll-readme-index" 8 | s.version = JekyllReadmeIndex::VERSION 9 | s.authors = ["Ben Balter"] 10 | s.email = ["ben.balter@github.com"] 11 | s.homepage = "https://github.com/benbalter/jekyll-readme-index" 12 | s.summary = "A Jekyll plugin to render a project's README as the site's index." 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 "rspec", "~> 3.5" 21 | s.add_development_dependency "rubocop", "~> 0.40" 22 | s.add_development_dependency "rubocop-jekyll", "~> 0.10.0" 23 | s.add_development_dependency "rubocop-performance", "~> 1.5" 24 | s.add_development_dependency "rubocop-rspec", "~> 1.3" 25 | end 26 | -------------------------------------------------------------------------------- /lib/jekyll-readme-index.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll" 4 | require "jekyll-readme-index/generator" 5 | require_relative "./jekyll/static_file_ext" 6 | 7 | module JekyllReadmeIndex 8 | end 9 | -------------------------------------------------------------------------------- /lib/jekyll-readme-index/generator.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module JekyllReadmeIndex 4 | class Generator < Jekyll::Generator 5 | INDEX_REGEX = %r!$|index\.(html?|xhtml|xml)$!i.freeze 6 | 7 | attr_accessor :site 8 | 9 | safe true 10 | priority :low 11 | 12 | CONFIG_KEY = "readme_index" 13 | ENABLED_KEY = "enabled" 14 | CLEANUP_KEY = "remove_originals" 15 | FRONTMATTER_KEY = "with_frontmatter" 16 | 17 | def initialize(site) 18 | @site = site 19 | end 20 | 21 | def generate(site) 22 | @site = site 23 | return if disabled? 24 | 25 | readmes.each do |readme| 26 | next unless should_be_index?(readme) 27 | 28 | site.pages << readme.to_page 29 | site.static_files.delete(readme) if cleanup? 30 | end 31 | 32 | if with_frontmatter? 33 | readmes_with_frontmatter.each do |readme| 34 | next unless should_be_index?(readme) 35 | 36 | readme.update_permalink 37 | end 38 | end 39 | end 40 | 41 | private 42 | 43 | # Returns an array of all READMEs as StaticFiles 44 | def readmes 45 | site.static_files.select { |file| file.relative_path =~ readme_regex } 46 | end 47 | 48 | def readmes_with_frontmatter 49 | site.pages.select { |file| ("/" + file.path) =~ readme_regex } 50 | end 51 | 52 | # Should the given readme be the containing directory's index? 53 | def should_be_index?(readme) 54 | return false unless readme 55 | 56 | !dir_has_index? File.dirname(readme.url) 57 | end 58 | 59 | # Does the given directory have an index? 60 | # 61 | # relative_path - the directory path relative to the site root 62 | def dir_has_index?(relative_path) 63 | relative_path << "/" unless relative_path.end_with? "/" 64 | regex = %r!^#{Regexp.escape(relative_path)}#{INDEX_REGEX}!i 65 | (site.pages + site.static_files).any? { |file| file.url =~ regex } 66 | end 67 | 68 | # Regexp to match a file path against to detect if the given file is a README 69 | def readme_regex 70 | @readme_regex ||= %r!/readme(#{Regexp.union(markdown_converter.extname_list)})$!i 71 | end 72 | 73 | def markdown_converter 74 | @markdown_converter ||= site.find_converter_instance(Jekyll::Converters::Markdown) 75 | end 76 | 77 | def option(key) 78 | site.config[CONFIG_KEY] && site.config[CONFIG_KEY][key] 79 | end 80 | 81 | def disabled? 82 | option(ENABLED_KEY) == false 83 | end 84 | 85 | def cleanup? 86 | option(CLEANUP_KEY) == true 87 | end 88 | 89 | def with_frontmatter? 90 | option(FRONTMATTER_KEY) == true 91 | end 92 | end 93 | end 94 | -------------------------------------------------------------------------------- /lib/jekyll-readme-index/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module JekyllReadmeIndex 4 | VERSION = "0.3.0" 5 | end 6 | -------------------------------------------------------------------------------- /lib/jekyll/static_file_ext.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Jekyll 4 | class StaticFile 5 | # Convert this static file to a Page 6 | def to_page 7 | page = Jekyll::Page.new(@site, @base, @dir, @name) 8 | page.data["permalink"] = File.dirname(url) + "/" 9 | page 10 | end 11 | end 12 | 13 | class Page 14 | def update_permalink 15 | data["permalink"] = File.dirname(url) + "/" 16 | @url = URL.new( 17 | :template => template, 18 | :placeholders => url_placeholders, 19 | :permalink => permalink 20 | ).to_s 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /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-readme-index.gemspec 8 | -------------------------------------------------------------------------------- /spec/fixtures/index-no-readme/index.html: -------------------------------------------------------------------------------- 1 |

Index

2 | -------------------------------------------------------------------------------- /spec/fixtures/no-readme-no-index/foo.md: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | # Test 5 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-html-index/index.html: -------------------------------------------------------------------------------- 1 |

Index

2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-html-index/readme.markdown: -------------------------------------------------------------------------------- 1 | # Readme 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-html-page-index/index.html: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: / 3 | --- 4 | 5 |

Index

6 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-html-page-index/readme.markdown: -------------------------------------------------------------------------------- 1 | # Readme 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-index-permalink/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: /index.html 3 | --- 4 | 5 | # Index 6 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-index-permalink/readme.markdown: -------------------------------------------------------------------------------- 1 | # Readme 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-index/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: / 3 | --- 4 | 5 | # Index 6 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-index/readme.markdown: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benbalter/jekyll-readme-index/a2830b058a7fd5bb0f045f9dae538c2124ca86a3/spec/fixtures/readme-and-index/readme.markdown -------------------------------------------------------------------------------- /spec/fixtures/readme-and-nested-readme/README.md: -------------------------------------------------------------------------------- 1 | # Top-level Readme Index 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-nested-readme/other.md: -------------------------------------------------------------------------------- 1 | # Some other file 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-nested-readme/with_readme/README.md: -------------------------------------------------------------------------------- 1 | # Second-level Readme 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-nested-readme/with_readme/other.md: -------------------------------------------------------------------------------- 1 | # some other nested file 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-nested-readme/with_readme_and_index/README.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-nested-readme/with_readme_and_index/index.html: -------------------------------------------------------------------------------- 1 |

Second-level Index

2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-and-nested-readme/without_readme/other.md: -------------------------------------------------------------------------------- 1 | # some other nested file 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-no-index/README.md: -------------------------------------------------------------------------------- 1 | # Jekyll Readme Index 2 | -------------------------------------------------------------------------------- /spec/fixtures/readme-with-frontmatter/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: page 3 | --- 4 | 5 | # README 6 | -------------------------------------------------------------------------------- /spec/fixtures/xhtml-index/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: /index.xhtml 3 | --- 4 | 5 | # XHTML Index 6 | -------------------------------------------------------------------------------- /spec/fixtures/xml-index/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | XML Index 4 | 5 | -------------------------------------------------------------------------------- /spec/jekyll-readme-index/generator_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | describe JekyllReadmeIndex::Generator do 4 | subject { described_class.new(site) } 5 | 6 | let(:overrides) { {} } 7 | let(:site) { fixture_site(fixture, overrides) } 8 | let(:readmes) { subject.send(:readmes) } 9 | let(:readmes_with_frontmatter) { subject.send(:readmes_with_frontmatter) } 10 | let(:dir) { "/" } 11 | let(:index?) { subject.send(:dir_has_index?, dir) } 12 | let(:readme) { readmes.find { |r| r.url =~ %r!#{dir}README\..*!i } } 13 | let(:readme_with_frontmatter) do 14 | readmes_with_frontmatter.find { |r| r.url =~ %r!#{dir}README\..*!i } 15 | end 16 | let(:page) { readme.to_page } 17 | let(:should_be_index?) { subject.send(:should_be_index?, readme) } 18 | let(:index_name) { "index.html" } 19 | let(:index_path) { File.join(site.dest, dir, index_name) } 20 | let(:index_content) { File.read(index_path) if File.exist?(index_path) } 21 | 22 | before do 23 | site.reset 24 | site.read 25 | end 26 | 27 | context "with a single README" do 28 | context "with a readme and no index" do 29 | let(:fixture) { "readme-no-index" } 30 | 31 | it "knows there's a readme" do 32 | expect(readme).not_to be_nil 33 | expect(readme.class).to eql(Jekyll::StaticFile) 34 | expect(readme.relative_path).to eql("/README.md") 35 | end 36 | 37 | it "knows there's no index" do 38 | expect(index?).to be(false) 39 | end 40 | 41 | it "knows the readme should be the index" do 42 | expect(should_be_index?).to be(true) 43 | end 44 | 45 | it "builds the index page" do 46 | expect(page.class).to eql(Jekyll::Page) 47 | expect(page.content).to eql("# Jekyll Readme Index\n") 48 | expect(page.url).to eql("/") 49 | end 50 | 51 | it "creates the index page" do 52 | subject.generate(site) 53 | expect(site.pages.map(&:name)).to include("README.md") 54 | expect(site.pages.map(&:url)).to include("/") 55 | end 56 | 57 | context "when building" do 58 | before { site.process } 59 | 60 | it "writes the index" do 61 | expect(index_path).to be_an_existing_file 62 | end 63 | 64 | it "renders the markdown to HTML" do 65 | expected = "

Jekyll Readme Index

\n" 66 | expect(index_content).to eql(expected) 67 | end 68 | end 69 | end 70 | 71 | context "with a readme and an index" do 72 | let(:fixture) { "readme-and-index" } 73 | 74 | it "knows there's a readme" do 75 | expect(readme).not_to be_nil 76 | expect(readme.class).to eql(Jekyll::StaticFile) 77 | expect(readme.relative_path).to eql("/readme.markdown") 78 | end 79 | 80 | it "knows there's an index" do 81 | expect(index?).to be(true) 82 | end 83 | 84 | it "knows the readme shouldn't be the index" do 85 | expect(should_be_index?).to be(false) 86 | end 87 | 88 | it "doesn't overwrite the index" do 89 | subject.generate(site) 90 | expect(site.pages.map(&:name)).not_to include("README.md") 91 | end 92 | 93 | context "when building" do 94 | before { site.process } 95 | 96 | it "writes the index" do 97 | expect(index_path).to be_an_existing_file 98 | end 99 | 100 | it "renders the markdown to HTML" do 101 | expected = "

Index

\n" 102 | expect(index_content).to eql(expected) 103 | end 104 | end 105 | end 106 | 107 | context "with a readme and a static HTML index" do 108 | let(:fixture) { "readme-and-html-index" } 109 | 110 | it "knows there's an index" do 111 | expect(index?).to be(true) 112 | end 113 | 114 | it "knows the readme shouldn't be the index" do 115 | expect(should_be_index?).to be(false) 116 | end 117 | 118 | it "doesn't overwrite the index" do 119 | subject.generate(site) 120 | expect(site.pages.map(&:name)).not_to include("README.md") 121 | end 122 | 123 | context "when building" do 124 | before { site.process } 125 | 126 | it "writes the index" do 127 | expect(index_path).to be_an_existing_file 128 | end 129 | 130 | it "renders the index as the index" do 131 | expected = "

Index

\n" 132 | expect(index_content).to eql(expected) 133 | end 134 | end 135 | end 136 | 137 | context "with a readme and a HTML index page" do 138 | let(:fixture) { "readme-and-html-page-index" } 139 | 140 | it "knows there's an index" do 141 | expect(index?).to be(true) 142 | end 143 | 144 | it "knows the readme shouldn't be the index" do 145 | expect(should_be_index?).to be(false) 146 | end 147 | 148 | it "doesn't overwrite the index" do 149 | subject.generate(site) 150 | expect(site.pages.map(&:name)).not_to include("README.md") 151 | end 152 | 153 | context "when building" do 154 | before { site.process } 155 | 156 | it "writes the index" do 157 | expect(index_path).to be_an_existing_file 158 | end 159 | 160 | it "renders the index as the index" do 161 | expected = "

Index

\n" 162 | expect(index_content).to eql(expected) 163 | end 164 | end 165 | end 166 | 167 | context "with a readme and an explicit permalink index" do 168 | let(:fixture) { "readme-and-index-permalink" } 169 | 170 | it "knows there's an index" do 171 | expect(index?).to be(true) 172 | end 173 | 174 | it "knows the readme shouldn't be the index" do 175 | expect(should_be_index?).to be(false) 176 | end 177 | 178 | it "doesn't overwrite the index" do 179 | subject.generate(site) 180 | expect(site.pages.map(&:name)).not_to include("README.md") 181 | end 182 | 183 | context "when building" do 184 | before { site.process } 185 | 186 | it "writes the index" do 187 | expect(index_path).to be_an_existing_file 188 | end 189 | 190 | it "renders the index as the index" do 191 | expected = "

Index

\n" 192 | expect(index_content).to eql(expected) 193 | end 194 | end 195 | end 196 | 197 | context "with no readme or index" do 198 | let(:fixture) { "no-readme-no-index" } 199 | 200 | it "knows there's no readme" do 201 | expect(readme).to be_nil 202 | end 203 | 204 | it "doesn't err out on should_be_index?" do 205 | expect(should_be_index?).to be(false) 206 | end 207 | 208 | it "knows there's an index" do 209 | expect(index?).to be(false) 210 | end 211 | 212 | context "when building" do 213 | before { site.process } 214 | 215 | it "doesn't write an index" do 216 | expect(index_path).not_to be_an_existing_file 217 | end 218 | end 219 | end 220 | 221 | context "with an index and no readme" do 222 | let(:fixture) { "index-no-readme" } 223 | 224 | it "knows there's no readme" do 225 | expect(readme).to be_nil 226 | end 227 | 228 | it "knows there's an index" do 229 | expect(index?).to be(true) 230 | end 231 | 232 | it "doesn't err out on should_be_index?" do 233 | expect(should_be_index?).to be(false) 234 | end 235 | 236 | context "when building" do 237 | before { site.process } 238 | 239 | it "writes the index" do 240 | expect(index_path).to be_an_existing_file 241 | end 242 | 243 | it "renders the markdown to HTML" do 244 | expected = "

Index

\n" 245 | expect(index_content).to eql(expected) 246 | end 247 | end 248 | end 249 | 250 | context "with an XML index" do 251 | let(:fixture) { "xml-index" } 252 | 253 | it "knows there's an index" do 254 | expect(index?).to be(true) 255 | end 256 | 257 | it "knows the readme shouldn't be the index" do 258 | expect(should_be_index?).to be(false) 259 | end 260 | 261 | it "doesn't overwrite the index" do 262 | subject.generate(site) 263 | expect(site.pages.map(&:name)).not_to include("README.md") 264 | end 265 | 266 | context "when building" do 267 | before { site.process } 268 | 269 | let(:index_name) { "index.xml" } 270 | 271 | it "writes the index" do 272 | expect(index_path).to be_an_existing_file 273 | end 274 | 275 | it "renders the index as the index" do 276 | expected = "\n XML Index\n\n" 277 | expect(index_content).to match(expected) 278 | end 279 | end 280 | end 281 | 282 | context "with an XHTML index" do 283 | let(:fixture) { "xhtml-index" } 284 | 285 | it "knows there's an index" do 286 | expect(index?).to be(true) 287 | end 288 | 289 | it "knows the readme shouldn't be the index" do 290 | expect(should_be_index?).to be(false) 291 | end 292 | 293 | it "doesn't overwrite the index" do 294 | subject.generate(site) 295 | expect(site.pages.map(&:name)).not_to include("README.md") 296 | end 297 | 298 | context "when building" do 299 | before { site.process } 300 | 301 | let(:index_name) { "index.xhtml" } 302 | 303 | it "writes the index" do 304 | expect(index_path).to be_an_existing_file 305 | end 306 | 307 | it "renders the index as the index" do 308 | expected = "

XHTML Index

\n" 309 | expect(index_content).to eql(expected) 310 | end 311 | end 312 | end 313 | end 314 | 315 | context "with multiple readmes" do 316 | let(:fixture) { "readme-and-nested-readme" } 317 | 318 | context "the root directory" do 319 | let(:dir) { "/" } 320 | 321 | it "knows there's a readme" do 322 | expect(readme).not_to be_nil 323 | expect(readme.class).to eql(Jekyll::StaticFile) 324 | expect(readme.relative_path).to eql("/README.md") 325 | end 326 | 327 | it "knows there's no index" do 328 | expect(index?).to be(false) 329 | end 330 | 331 | it "knows the readme should be the index" do 332 | expect(should_be_index?).to be(true) 333 | end 334 | 335 | it "builds the index page" do 336 | expect(page.class).to eql(Jekyll::Page) 337 | expect(page.content).to eql("# Top-level Readme Index\n") 338 | expect(page.url).to eql("/") 339 | end 340 | 341 | it "creates the index page" do 342 | subject.generate(site) 343 | expect(site.pages.map(&:name)).to include("README.md") 344 | expect(site.pages.map(&:url)).to include("/") 345 | end 346 | 347 | context "when building" do 348 | before { site.process } 349 | 350 | it "writes the index" do 351 | expect(index_path).to be_an_existing_file 352 | end 353 | 354 | it "renders the markdown to HTML" do 355 | expected = "

Top-level Readme Index

\n" 356 | expect(index_content).to eql(expected) 357 | end 358 | end 359 | end 360 | 361 | context "a subfolder with a readme" do 362 | let(:dir) { "/with_readme/" } 363 | 364 | it "knows there's a readme" do 365 | expect(readme).not_to be_nil 366 | expect(readme.class).to eql(Jekyll::StaticFile) 367 | expect(readme.relative_path).to eql("#{dir}README.md") 368 | end 369 | 370 | it "knows there's no index" do 371 | expect(index?).to be(false) 372 | end 373 | 374 | it "knows the readme should be the index" do 375 | expect(should_be_index?).to be(true) 376 | end 377 | 378 | it "builds the index page" do 379 | expect(page.class).to eql(Jekyll::Page) 380 | expect(page.content).to eql("# Second-level Readme\n") 381 | expect(page.url).to eql(dir) 382 | end 383 | 384 | it "creates the index page" do 385 | subject.generate(site) 386 | expect(site.pages.map(&:name)).to include("README.md") 387 | expect(site.pages.map(&:url)).to include(dir) 388 | end 389 | 390 | context "when building" do 391 | before { site.process } 392 | 393 | it "writes the index" do 394 | expect(index_path).to be_an_existing_file 395 | end 396 | 397 | it "renders the markdown to HTML" do 398 | expected = "

Second-level Readme

\n" 399 | expect(index_content).to eql(expected) 400 | end 401 | end 402 | end 403 | 404 | context "a subfolder with a readme and an index" do 405 | let(:dir) { "/with_readme_and_index/" } 406 | 407 | it "knows there's a readme" do 408 | expect(readme).not_to be_nil 409 | expect(readme.class).to eql(Jekyll::StaticFile) 410 | expect(readme.relative_path).to eql("#{dir}README.md") 411 | end 412 | 413 | it "knows there's an index" do 414 | expect(index?).to be(true) 415 | end 416 | 417 | it "knows the readme shouldn't be the index" do 418 | expect(should_be_index?).to be(false) 419 | end 420 | 421 | context "when building" do 422 | before { site.process } 423 | 424 | it "writes the index" do 425 | expect(index_path).to be_an_existing_file 426 | end 427 | 428 | it "renders the index as the index" do 429 | expected = "

Second-level Index

\n" 430 | expect(index_content).to eql(expected) 431 | end 432 | end 433 | end 434 | 435 | context "a subfolder without a readme" do 436 | let(:dir) { "/without_readme" } 437 | 438 | it "knows there's no readme" do 439 | expect(readme).to be_nil 440 | end 441 | 442 | it "knows the readme shouldn't be the index" do 443 | expect(should_be_index?).to be(false) 444 | end 445 | 446 | context "when building" do 447 | before { site.process } 448 | 449 | it "doesn't write the index" do 450 | expect(index_path).not_to be_an_existing_file 451 | end 452 | end 453 | end 454 | end 455 | 456 | context "with frontmatter" do 457 | let(:overrides) { { "readme_index" => { "with_frontmatter" => true } } } 458 | 459 | context "with a single README" do 460 | let(:fixture) { "readme-with-frontmatter" } 461 | 462 | it "knows there's a readme" do 463 | expect(readme_with_frontmatter).not_to be_nil 464 | expect(readme_with_frontmatter.class).to eql(Jekyll::Page) 465 | expect(readme_with_frontmatter.path).to eql("README.md") 466 | end 467 | 468 | it "creates the index page" do 469 | subject.generate(site) 470 | expect(site.pages.map(&:name)).to include("README.md") 471 | expect(site.pages.map(&:url)).to include("/") 472 | end 473 | end 474 | end 475 | 476 | context "cleanup" do 477 | let(:overrides) { { "readme_index" => { "remove_originals" => true } } } 478 | 479 | context "with a single README" do 480 | context "with a readme and no index" do 481 | let(:fixture) { "readme-no-index" } 482 | 483 | it "creates the index page" do 484 | subject.generate(site) 485 | expect(site.pages.map(&:name)).to include("README.md") 486 | expect(site.pages.map(&:url)).to include("/") 487 | end 488 | 489 | it "removes the readme file" do 490 | subject.generate(site) 491 | expect(site.static_files.map(&:relative_path)).not_to include("/README.md") 492 | end 493 | end 494 | 495 | context "with a readme and an index" do 496 | let(:fixture) { "readme-and-index" } 497 | 498 | it "doesn't overwrite the index" do 499 | subject.generate(site) 500 | expect(site.pages.map(&:name)).not_to include("readme.markdown") 501 | end 502 | 503 | it "doesn't remove the readme file" do 504 | subject.generate(site) 505 | expect(site.static_files.map(&:relative_path)).to include("/readme.markdown") 506 | end 507 | end 508 | 509 | context "with a readme and a static HTML index" do 510 | let(:fixture) { "readme-and-html-index" } 511 | 512 | it "doesn't overwrite the index" do 513 | subject.generate(site) 514 | expect(site.pages.map(&:name)).not_to include("readme.markdown") 515 | end 516 | 517 | it "doesn't remove the readme file" do 518 | subject.generate(site) 519 | expect(site.static_files.map(&:relative_path)).to include("/readme.markdown") 520 | end 521 | end 522 | 523 | context "with a readme and a HTML index page" do 524 | let(:fixture) { "readme-and-html-page-index" } 525 | 526 | it "doesn't overwrite the index" do 527 | subject.generate(site) 528 | expect(site.pages.map(&:name)).not_to include("readme.markdown") 529 | end 530 | 531 | it "doesn't remove the readme file" do 532 | subject.generate(site) 533 | expect(site.static_files.map(&:relative_path)).to include("/readme.markdown") 534 | end 535 | end 536 | 537 | context "with a readme and an explicit permalink index" do 538 | let(:fixture) { "readme-and-index-permalink" } 539 | 540 | it "doesn't overwrite the index" do 541 | subject.generate(site) 542 | expect(site.pages.map(&:name)).not_to include("readme.markdown") 543 | end 544 | 545 | it "doesn't remove the readme file" do 546 | subject.generate(site) 547 | expect(site.static_files.map(&:relative_path)).to include("/readme.markdown") 548 | end 549 | end 550 | end 551 | 552 | context "with multiple readmes" do 553 | let(:fixture) { "readme-and-nested-readme" } 554 | 555 | context "the root directory" do 556 | let(:dir) { "/" } 557 | 558 | it "creates the index page" do 559 | subject.generate(site) 560 | expect(site.pages.map(&:name)).to include("README.md") 561 | expect(site.pages.map(&:url)).to include("/") 562 | end 563 | 564 | it "does remove the root readme file" do 565 | subject.generate(site) 566 | readme = "/readme.markdown" 567 | expect(site.static_files.map(&:relative_path)).not_to include(readme) 568 | end 569 | end 570 | 571 | context "a subfolder with a readme" do 572 | let(:dir) { "/with_readme/" } 573 | 574 | it "creates the index page" do 575 | subject.generate(site) 576 | expect(site.pages.map(&:name)).to include("README.md") 577 | expect(site.pages.map(&:url)).to include(dir) 578 | end 579 | 580 | it "does remove the subfolder readme file" do 581 | subject.generate(site) 582 | readme = "/with_readme/readme.markdown" 583 | expect(site.static_files.map(&:relative_path)).not_to include(readme) 584 | end 585 | end 586 | end 587 | end 588 | 589 | context "when disabled" do 590 | let(:fixture) { "readme-no-index" } 591 | let(:overrides) { { "readme_index" => { "enabled" => false } } } 592 | 593 | it "doesn't create the index page" do 594 | subject.generate(site) 595 | expect(site.pages.map(&:name)).not_to include("README.md") 596 | expect(site.pages.map(&:url)).not_to include("/") 597 | end 598 | end 599 | 600 | context "when explicitly enabled" do 601 | let(:fixture) { "readme-no-index" } 602 | let(:overrides) { { "readme_index" => { "enabled" => true } } } 603 | 604 | it "does create the index page" do 605 | subject.generate(site) 606 | expect(site.pages.map(&:name)).to include("README.md") 607 | expect(site.pages.map(&:url)).to include("/") 608 | end 609 | end 610 | end 611 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "jekyll-readme-index" 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.shared_context_metadata_behavior = :apply_to_host_groups 15 | config.example_status_persistence_file_path = "spec/examples.txt" 16 | 17 | config.default_formatter = "doc" if config.files_to_run.one? 18 | 19 | config.order = :random 20 | Kernel.srand config.seed 21 | end 22 | 23 | Jekyll.logger.adjust_verbosity(:quiet => true) 24 | 25 | def fixture_path(fixture) 26 | File.expand_path "./fixtures/#{fixture}", File.dirname(__FILE__) 27 | end 28 | 29 | def fixture_site(fixture, override = {}) 30 | default_config = { "source" => fixture_path(fixture) } 31 | config = Jekyll::Utils.deep_merge_hashes(default_config, override) 32 | config = Jekyll.configuration(config) 33 | Jekyll::Site.new(config) 34 | end 35 | 36 | RSpec::Matchers.define :be_an_existing_file do 37 | match { |path| File.exist?(path) } 38 | end 39 | 40 | fixture_site("readme-no-index").process 41 | --------------------------------------------------------------------------------