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

Implemented Categories Support #293

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

manikmagar
Copy link
Member

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

  • If categories.enable is not false and no categories are provided for post then category.default is applied to post.
  • First category is also available with primary_category key in model.
  • If 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 page template.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 to true then all category pages are rendered without extension.

Test cases

Appropriate test cases have been added under src/test/java with its resources under src/test/resources.

@coveralls
Copy link

coveralls commented Jun 25, 2016

Coverage Status

Coverage increased (+1.3%) to 66.279% when pulling c252f14 on manikmagar:mm-jbake-categories into 6e4a165 on jbake-org:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.7%) to 69.226% when pulling e8299cd on manikmagar:mm-jbake-categories into 7248d37 on jbake-org:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.8%) to 69.325% when pulling e8299cd on manikmagar:mm-jbake-categories into 7248d37 on jbake-org:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+1.8%) to 69.325% when pulling e8299cd on manikmagar:mm-jbake-categories into 7248d37 on jbake-org:master.

@coveralls
Copy link

coveralls commented Jul 4, 2016

Coverage Status

Coverage increased (+1.6%) to 69.141% when pulling b192546 on manikmagar:mm-jbake-categories into 7248d37 on jbake-org:master.

@jonbullock
Copy link
Member

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 jonbullock added this to the v3.0.0 milestone Sep 26, 2016
@jonbullock jonbullock self-assigned this Sep 26, 2016
@manikmagar
Copy link
Member Author

@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.

@jonbullock
Copy link
Member

jonbullock commented May 12, 2017

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.

@manikmagar
Copy link
Member Author

Thank you @jonbullock , I will eagerly be waiting for 2.7.0 👍

@manikmagar
Copy link
Member Author

This was implemented a while back (on maven), I think I will rebase to current master and update it.

@jonbullock
Copy link
Member

It would be great if you could thanks @manikmagar

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 79.068% when pulling d602719 on manikmagar:mm-jbake-categories into 1733a2a on jbake-org:master.

Copy link

@georgleber georgleber left a 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"));

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

Copy link
Member Author

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) {

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);

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));

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) {

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants