-
Notifications
You must be signed in to change notification settings - Fork 327
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
Implemented Categories Support #293
base: master
Are you sure you want to change the base?
Conversation
1 similar comment
Thanks for taking the time to submit this @manikmagar I'll review this properly once v2.5.0 is out and planning starts for the next release. |
@jonbullock Any date for 3.0 release? This is one of the few things that's either requiring me to use my own version of jbake or just skip categories and use tags (not so much good option). I would prefer to use standard jbake version :) Thanks. |
No date planned at present. However I'm leaning towards having a 2.7.0 release, especially as some big changes are lined up for 3.0.0 and this would be an ideal candidate for another 2.x release. |
Thank you @jonbullock , I will eagerly be waiting for 2.7.0 👍 |
This was implemented a while back (on maven), I think I will rebase to current master and update it. |
It would be great if you could thanks @manikmagar |
b192546
to
d602719
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The category view is a very good extension. I want to make only a few suggestions.
DocumentList docs = this.getAllCategoriesFromPublishedPosts(); | ||
Set<String> result = new HashSet<String>(); | ||
for (Map<String, Object> document : docs) { | ||
String[] categories = DBUtil.toStringArray(document.get("categories")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to reference the crawler attribute instead of using a hard coded string value: Crawler.Attributes.CATEGORIES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @GeorgHenkel, Thanks. I will make the changes.
@@ -140,6 +141,31 @@ public void processBody(final ParserContext context) {} | |||
content.put(Crawler.Attributes.TAGS, tags); | |||
} | |||
|
|||
// If categories are not disabled then add a default category | |||
if(config.getBoolean(Keys.CATEGORIES_ENABLE)){ | |||
if (content.get("categories") != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here it would be better to use Crawler.Attributes.CATEGORIES
instead of a string.
categories[i]=categories[i].replace(" ", "-"); | ||
} | ||
} | ||
content.put("categories", categories); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here it would be better to use Crawler.Attributes.CATEGORIES
instead of the string value "categories"
if (config.getBoolean(Keys.CATEGORY_SANITIZE,false)) { | ||
defaultCategory = defaultCategory.replace(" ", "-"); | ||
} | ||
content.put("categories", ArrayUtils.toArray(defaultCategory)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here it would be better to use Crawler.Attributes.CATEGORIES instead of the string value "categories"
} | ||
content.put("primary_category", ((String[])content.get("categories"))[0]); | ||
} else { | ||
if (content.get("categories") != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here it would be better to use Crawler.Attributes.CATEGORIES instead of the string value "categories"
Implemented Categories Support for Posts.
Categories configuration controls -
template.category.file=category.ftl
(This is for rendering individual category page)template.categories.file=categories.ftl
(This is for rendering all categories list page to prevent directory listing on {site.host}/categories/ url.categories.enable=true
render.categories=true
category.default=Uncategorized
categories.path=categories
categories.sanitize=false
Adding categories in content
Add an attribute
categories=Category1, Category2
categories.enable
is not false and no categories are provided for post thencategory.default
is applied to post.primary_category
key in model.categories.enable
is false and categories are still provided in content, then those are ignored with a warning in log.Accessing categories in templates
all_categories
- All categories from all published content. This variable is available on templates.category_posts
- On a single category pagetemplate.category.file
, this variable is available and provides access to posts marked with category being displayed on page.Extensionless Support
If
uri.noExtension
is set totrue
then all category pages are rendered without extension.Test cases
Appropriate test cases have been added under
src/test/java
with its resources undersrc/test/resources
.