-
Notifications
You must be signed in to change notification settings - Fork 208
Feed by tag #264
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
Feed by tag #264
Changes from 27 commits
c2d2f3d
a5d5881
0bb481c
223343b
d2d31d7
89eb58a
7601bc6
ee59d9e
c60d01e
f74c32f
e622a6f
8db0621
6a7bd53
5f7d27a
665cfba
67d817d
f975bb5
3eb88ac
05ee178
76bbf81
d36c93a
3d8e51e
9216296
93c69a8
9cd44b4
281b49f
fde5155
36f4ea8
2b21c5d
27f8932
d982285
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ def generate(site) | |||||||
| @site.pages << make_page(path, :collection => name, :category => category) | ||||||||
| end | ||||||||
| end | ||||||||
| generate_feed_by_tag if config["tags"] && [email protected]? | ||||||||
| end | ||||||||
|
|
||||||||
| private | ||||||||
|
|
@@ -69,6 +70,32 @@ def collections | |||||||
| @collections | ||||||||
| end | ||||||||
|
|
||||||||
| def generate_feed_by_tag | ||||||||
| tags_config = config["tags"] | ||||||||
| tags_config = {} unless tags_config.is_a?(Hash) | ||||||||
|
|
||||||||
| except = tags_config["except"] || [] | ||||||||
| only = tags_config["only"] || @site.tags.keys | ||||||||
| tags_pool = only - except | ||||||||
| tags_path = tags_config["path"] || "/feed/by_tag/" | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if I pass in a malicious path here via the site's config? (e.g.,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets passed to the same "make_page" function as generating the main feed uses. Honestly I'm not sure what happens with malicious paths get used, I assumed that function already included sanity checking for the path. The only change I made to that function was to allow it to include the option to pass in the tag you want a feed for.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benbalter In reality the # jekyll/lib/jekyll/page.rb
def path
data.fetch("path") { relative_path }
end
# The path to the page source file, relative to the site source
def relative_path
@relative_path ||= File.join(*[@dir, @name].map(&:to_s).reject(&:empty?)).sub(%r!\A\/!, "")
end
jekyll-feed/lib/jekyll-feed/page-without-a-file.rb Lines 5 to 7 in 9cda8c4
That said, your observation cannot be left disregarded (also present in the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Added a test for this in 93c69a8 |
||||||||
|
|
||||||||
| generate_tag_feed(tags_pool, tags_path) | ||||||||
| end | ||||||||
|
|
||||||||
| def generate_tag_feed(tags_pool, tags_path) | ||||||||
| tags_pool.each do |tag| | ||||||||
| # allow only tags with basic alphanumeric characters and underscore to keep | ||||||||
| # feed path simple. | ||||||||
| next if tag =~ %r![^a-zA-Z0-9_]! | ||||||||
|
|
||||||||
| Jekyll.logger.info "Jekyll Feed:", "Generating feed for posts tagged #{tag}" | ||||||||
| path = "#{tags_path}#{tag}.xml" | ||||||||
| next if file_exists?(path) | ||||||||
|
|
||||||||
| @site.pages << make_page(path, :tags => tag) | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| # Path to feed.xml template file | ||||||||
| def feed_source_path | ||||||||
| @feed_source_path ||= File.expand_path "feed.xml", __dir__ | ||||||||
|
|
@@ -85,15 +112,16 @@ def file_exists?(file_path) | |||||||
|
|
||||||||
| # Generates contents for a file | ||||||||
|
|
||||||||
| def make_page(file_path, collection: "posts", category: nil) | ||||||||
| def make_page(file_path, collection: "posts", category: nil, tags: nil) | ||||||||
| PageWithoutAFile.new(@site, __dir__, "", file_path).tap do |file| | ||||||||
| file.content = feed_template | ||||||||
| file.data.merge!( | ||||||||
| "layout" => nil, | ||||||||
| "sitemap" => false, | ||||||||
| "xsl" => file_exists?("feed.xslt.xml"), | ||||||||
| "collection" => collection, | ||||||||
| "category" => category | ||||||||
| "category" => category, | ||||||||
| "tags" => tags | ||||||||
| ) | ||||||||
| file.output | ||||||||
| end | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| excerpt: "Foo" | ||
| image: "/image.png" | ||
| category: news | ||
| tags: | ||
| - test | ||
| --- | ||
|
|
||
| # December the twelfth, actually. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| --- | ||
| image: https://cdn.example.org/absolute.png?h=188&w=250 | ||
| category: news | ||
| tags: | ||
| - test | ||
| --- | ||
|
|
||
| March the second! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| tags: | ||
| - '"/><VADER>' | ||
| - test | ||
| image: | ||
| path: "/object-image.png" | ||
| categories: updates jekyll | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| --- | ||
| last_modified_at: 2015-05-12T13:27:59+00:00 | ||
| tags: | ||
| - test | ||
| - fail | ||
| --- | ||
|
|
||
| Please don't modify this file. It's modified time is important. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| --- | ||
| tag: nonarray | ||
| --- | ||
|
|
||
| {% capture liquidstring %} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| --- | ||
| author: Pat | ||
| lang: en | ||
| tags: | ||
| - test | ||
| --- | ||
|
|
||
| <pre>Line 1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,9 @@ author: | |
| name: Ben | ||
| uri: "http://ben.balter.com" | ||
| email: [email protected] | ||
| tags: | ||
| - test | ||
| - success | ||
| --- | ||
|
|
||
| # December the twelfth, actually. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| --- | ||
| tags: | ||
| - test | ||
| - fail | ||
| feed: | ||
| excerpt_only: true | ||
| --- | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.