Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Prototype" pages feature for paginated archives of categories, tags, and other front matter values #11

Merged
merged 3 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.md
*.html
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# master

# 0.11.0 / 2020-04-21

**Prototype Pages**

You can now create a page, say `categories/category.html`, and add a `prototype` config
to the Front Matter:

```yaml
layout: default
title: Posts in category :prototype-term
prototype:
term: category
```

And then all the site's different categories will have archives pages at this location
(e.g. `categories/awesome-movies`, `categories/my-cool-vacation`, etc.) It enables
pagination automatically, so you'd just use `paginator.documents` to loop through the
posts.

# 0.10.2 / 2020-04-19

**Automatic Yarn Step for New Plugins**
Expand Down
24 changes: 24 additions & 0 deletions bridgetown-core/features/pagination.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ Feature: Site pagination
| 3 | 1 | 6 |
| 4 | 1 | 7 |

Scenario Outline: Paginate posts with tags
Given I have a configuration file with:
| key | value |
| pagination | { enabled: true, per_page: <num> } |
And I have a _layouts directory
And I have an "index.html" page with pagination "{enabled: true, tag: scary}" that contains "{{ paginator.documents.size }} {{ paginator.documents[0].title }}"
And I have a _posts directory
And I have the following posts:
| title | date | layout | tags | content |
| Wargames | 2009-03-27 | default | strange difficult | The only winning move is not to play. |
| Wargames2 | 2009-04-27 | default | strange, scary | The only winning move is not to play2. |
| Wargames3 | 2009-05-27 | default | ["awful news", "scary"] | The only winning move is not to play3. |
| Wargames4 | 2009-06-27 | default | terrible; scary | The only winning move is not to play4. |
When I run bridgetown build
Then the output/page/<exist> directory should exist
And the "output/page/<exist>/index.html" file should exist
And I should see "<posts>" in "output/page/<exist>/index.html"
And the "output/page/<not_exist>/index.html" file should not exist

Examples:
| num | exist | posts | not_exist | title |
| 1 | 3 | 1 | 4 | Wargames2 |
| 2 | 2 | 2 | 3 | Wargames3 |

# TODO: this isn't working currently…wondering if it "ever" worked
Scenario Outline: Setting a custom pagination path with numbered html pages
Given this scenario should be skipped
Expand Down
85 changes: 85 additions & 0 deletions bridgetown-core/features/prototype_pages.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Feature: Prototype Pages
In order to auto-generate category, tag, etc. archives
As a blog's user
I want create a prototype page and then divide matching posts in several pages

Scenario Outline: Generate category pages and paginate
Given I have a configuration file with:
| key | value |
| pagination | { enabled: true, per_page: <num> } |
And I have a _layouts directory
And I have a categories directory
And I have an "categories/category.html" page with prototype "{term: category}" that contains "{{ paginator.documents.size }} {{ paginator.documents[0].title }}"
And I have a _posts directory
And I have the following posts:
| title | date | category | content |
| Wargames | 2009-03-27 | This Means War | The only winning move is not to play. |
| Wargames2 | 2009-04-27 | This Means War | The only winning move is not to play2. |
| Wargames3 | 2009-05-27 | This Means War | The only winning move is not to play3. |
| Wargames4 | 2009-06-27 | This Means War | The only winning move is not to play4. |
| Peace5 | 2009-07-27 | This Means Peace | Peace in our time. |
When I run bridgetown build
Then the output/categories/this-means-war/page/<exist> directory should exist
And the "output/categories/this-means-war/page/<exist>/index.html" file should exist
And I should see "<posts>" in "output/categories/this-means-war/page/<exist>/index.html"
And the "output/categories/this-means-war/page/<not_exist>/index.html" file should not exist
And the "output/categories/this-means-peace/index.html" file should exist
And the output/categories/this-means-peace/page/2 directory should not exist

Examples:
| num | exist | posts | not_exist | title |
| 1 | 4 | 1 | 5 | Wargames |
| 2 | 2 | 2 | 3 | Wargames2 |
| 3 | 2 | 1 | 3 | Wargames3 |

Scenario Outline: Generate tag pages and paginate
Given I have a configuration file with:
| key | value |
| pagination | { enabled: true, per_page: <num> } |
And I have a _layouts directory
And I have a tags directory
And I have an "tags/tag.html" page with prototype "{term: tag}" that contains "#{{ page.tag }} {{ paginator.documents.size }} {{ paginator.documents[0].title }}"
And I have a _posts directory
And I have the following posts:
| title | date | tags | content |
| Wargames | 2009-03-27 | strange difficult | The only winning move is not to play. |
| Wargames2 | 2009-04-27 | strange, scary | The only winning move is not to play2. |
| Wargames3 | 2009-05-27 | ["awful news", "scary"] | The only winning move is not to play3. |
| Wargames4 | 2009-06-27 | terrible scary | The only winning move is not to play4. |
When I run bridgetown build
Then the output/tags/scary/page/<exist> directory should exist
And the "output/tags/scary/page/<exist>/index.html" file should exist
And I should see "#scary" in "output/tags/scary/page/<exist>/index.html"
And I should see "<posts>" in "output/tags/scary/page/<exist>/index.html"
And the "output/tags/scary/page/<not_exist>/index.html" file should not exist
And the "output/tags/awful-news/index.html" file should exist

Examples:
| num | exist | posts | not_exist | title |
| 1 | 3 | 1 | 4 | Wargames2 |
| 2 | 2 | 2 | 3 | Wargames3 |

Scenario Outline: Generate author pages and paginate
Given I have a configuration file with:
| key | value |
| pagination | { enabled: true, per_page: <num> } |
And I have a _layouts directory
And I have a authors directory
And I have an "authors/author.html" page with prototype "{term: author}" that contains "{{ paginator.documents.size }} {{ paginator.documents[0].title }}"
And I have a _posts directory
And I have the following posts:
| title | date | author | content |
| Wargames | 2009-03-27 | ["john doe", "jenny"] | The only winning move is not to play. |
| Wargames2 | 2009-04-27 | jackson | The only winning move is not to play2. |
| Wargames3 | 2009-05-27 | melinda, jackson | The only winning move is not to play3. |
| Wargames4 | 2009-06-27 | fred ; jackson | The only winning move is not to play4. |
When I run bridgetown build
Then the output/authors/jackson/page/<exist> directory should exist
And the "output/authors/jackson/page/<exist>/index.html" file should exist
And I should see "<posts>" in "output/authors/jackson/page/<exist>/index.html"
And the "output/authors/jackson/page/<not_exist>/index.html" file should not exist

Examples:
| num | exist | posts | not_exist | title |
| 1 | 3 | 1 | 4 | Wargames2 |
| 2 | 2 | 2 | 3 | Wargames3 |
14 changes: 14 additions & 0 deletions bridgetown-core/features/site_configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,17 @@ Feature: Site configuration
And the output directory should exist
And I should see "FOO" in "output/index.html"
And I should not see " " in "output/index.html"

Scenario: Opt-out of slugified categories
Given I have a _posts directory
And I have the following post:
| title | date | category | content |
| Star Wars | 2009-03-27 | Big Reveals | Luke, I am your father. |
And I have a configuration file with:
| key | value |
| slugify_categories | false |
| permalink | simple |
When I run bridgetown build
Then I should get a zero exit status
And the output directory should exist
And I should see "I am your father" in "output/big reveals/star-wars/index.html"
56 changes: 23 additions & 33 deletions bridgetown-core/features/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@

#

Given /skipped/ do
Given %r!skipped! do
skip_this_scenario
end

#

Given(%r!^I have a blank site in "(.*)"$!) do |path|
unless File.exist?(path)
then FileUtils.mkdir_p(path)
end
FileUtils.mkdir_p(path) unless File.exist?(path)
end

#
Expand All @@ -40,17 +38,17 @@
#

Given(%r!^I have an? "(.*)" page(?: with (.*) "(.*)")? that contains "(.*)"$!) do |file, key, value, text|
unless file.include?("srcsite")
FileUtils.mkdir_p("src") unless File.exist?("src")
File.write(File.join("src", file), <<~DATA)
if file.include?("srcsite")
File.write(file, <<~DATA)
---
#{key || "layout"}: #{value || "none"}
---

#{text}
DATA
else
File.write(file, <<~DATA)
FileUtils.mkdir_p("src") unless File.exist?("src")
File.write(File.join("src", file), <<~DATA)
---
#{key || "layout"}: #{value || "none"}
---
Expand All @@ -63,11 +61,11 @@
#

Given(%r!^I have an? "(.*)" file that contains "(.*)"$!) do |file, text|
unless Paths.root_files.include?(file.split("/").first)
if Paths.root_files.include?(file.split("/").first)
File.write(file, text)
else
FileUtils.mkdir_p("src") unless File.exist?("src")
File.write(File.join("src", file), text)
else
File.write(file, text)
end
end

Expand All @@ -84,11 +82,11 @@
#

Given(%r!^I have an? "(.*)" file with content:$!) do |file, text|
unless Paths.root_files.include?(file.split("/").first)
if Paths.root_files.include?(file.split("/").first)
File.write(file, text)
else
FileUtils.mkdir_p("src") unless File.exist?("src")
File.write(File.join("src", file), text)
else
File.write(file, text)
end
end

Expand All @@ -108,13 +106,11 @@
#

Given(%r!^I have an? \"?(.*?)\"? directory$!) do |dir|
unless Paths.root_files.include?(dir)
dir_in_src = File.join("src", dir)
unless File.directory?(dir_in_src)
then FileUtils.mkdir_p(dir_in_src)
end
else
if Paths.root_files.include?(dir)
FileUtils.mkdir_p(dir)
else
dir_in_src = File.join("src", dir)
FileUtils.mkdir_p(dir_in_src) unless File.directory?(dir_in_src)
end
end

Expand All @@ -126,7 +122,7 @@
ext = input_hash["type"] || "markdown"
filename = "#{title}.#{ext}" if %w(page).include?(status)
before, after = location(folder, direction)
dest_folder = "_posts" if status == "post"
dest_folder = "_posts" if status == "post"
dest_folder = "" if status == "page"

if status == "post"
Expand Down Expand Up @@ -239,27 +235,21 @@

When(%r!^I run bridgetown(.*)$!) do |args|
run_bridgetown(args)
if args.include?("--verbose") || ENV["DEBUG"]
warn "\n#{bridgetown_run_output}\n"
end
warn "\n#{bridgetown_run_output}\n" if args.include?("--verbose") || ENV["DEBUG"]
end

#

When(%r!^I run bundle(.*)$!) do |args|
run_bundle(args)
if args.include?("--verbose") || ENV["DEBUG"]
warn "\n#{bridgetown_run_output}\n"
end
warn "\n#{bridgetown_run_output}\n" if args.include?("--verbose") || ENV["DEBUG"]
end

#

When(%r!^I run gem(.*)$!) do |args|
run_rubygem(args)
if args.include?("--verbose") || ENV["DEBUG"]
warn "\n#{bridgetown_run_output}\n"
end
warn "\n#{bridgetown_run_output}\n" if args.include?("--verbose") || ENV["DEBUG"]
end

#
Expand All @@ -279,10 +269,10 @@
#

When(%r!^I delete the file "(.*)"$!) do |file|
unless Paths.root_files.include?(file)
File.delete(File.join("src", file))
else
if Paths.root_files.include?(file)
File.delete(file)
else
File.delete(File.join("src", file))
end
end

Expand Down
1 change: 1 addition & 0 deletions bridgetown-core/lib/bridgetown-core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Configuration < Hash
"encoding" => "utf-8",
"markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
"strict_front_matter" => false,
"slugify_categories" => true,

# Filtering Content
"limit_posts" => 0,
Expand Down
6 changes: 5 additions & 1 deletion bridgetown-core/lib/bridgetown-core/drops/url_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def slug
def categories
category_set = Set.new
Array(@obj.data["categories"]).each do |category|
category_set << category.to_s.downcase
category_set << if @obj.site.config["slugify_categories"]
Utils.slugify(category.to_s)
else
category.to_s.downcase
end
end
category_set.to_a.join("/")
end
Expand Down
Loading