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

Create category pages to show posts associated with a category and add support for multiple blogs #70

Closed
wants to merge 7 commits into from

Conversation

makkoncept
Copy link
Member

Fixes #54

Description

  • Add blog-categories and blog-category models and templates.
  • Add categories.html macro.
  • Made the links and query dynamic to support multiple blogs.
  • Used this script to extract all the categories from archives/old-tech-blog/ and make file structure under blog-categories/old-tech-blog/. All 94 unique categories were ported.

Other information
Please refer the screenshots below.

The second link was for local testing
category1

All Categories of old-tech-blog
Screenshot from 2019-04-06 02-11-08

Blog posts for Individual Category
Screenshot from 2019-04-06 02-11-58

Category links in the blog are working
Screenshot from 2019-04-06 02-57-11

Checklist:

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master branch of the repository.
  • My commit messages follow best practices.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

@makkoncept makkoncept requested a review from a team April 5, 2019 21:33
hidden = yes

[children]
replaced_with = site.query('archives/' + this.parent.path.split('/')[-1]).filter(F.categories.contains(this))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All blogs will not be under archives.

Copy link
Member Author

@makkoncept makkoncept Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry @kgodey, I didn't get the email notification for this.
Okay, I will look into it and try to structure it differently.

@@ -0,0 +1 @@
name: w3c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these files need to be created manually whenever a new category is created? How do we ensure that that happens?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we have to manually add it either through the admin panel or in the folder structure. I checked the official documentation and their example is also implemented this way.
I will look into it and update you about it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgodey We can make categories of type=checkboxes instead of strings to make sure that we have created a category before we can use it and also we can still mark multiple categories.

But I am facing a problem in making the source dynamic.

If we have for example two blogs, foo and bar. Then there will be blog-categories/foo/* and blog-categories/bar/* directories to hold respective categories.
In blog-post.ini model:

[fields.categories]
label = Categories
type = checkboxes
source = site.query(<dynamic source=?>)

I have tried source = site.query('/blog-categories/' + this.parent.path.split('/')[-1]), but it is producing this is undefined error. Infact, I think we cannot use any variables in user defined model fields but I may be wrong.
I have searched through the documentation and couldn't find any solution.
Is there any way we can solve this problem?
Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving blog-categories into the old-tech-blog parent folder (I would probably just rename it to categories) since the categories are associated with that blog. You could move the blog entries into their own folder if needed (for example, see the project-ideas-collection folder under gsoc-2019) so that the top level folders would just be categories, entries, and (later) authors. You should be able to build the path from that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @kgodey for this recommendation. I have tried this locally and everything works well. The structure is cleaner this way.
I am going to test it more by adding dummy blogs.
Shall I make another PR for this as significant editing and restructuring are happening?

Also, I think we will only be able to set type=strings for [fields.categories] under blog-post.ini model. For type=checkboxes, all categories must reside under a common path(which is not happening in this implementation) as demonstrated in this lektor guide. Everything will work normally, but we still have to make sure that we make foo category file under <blog-name>/categories folder for the category link foo in a blog post to work properly.
What are your thoughts on this?
Thanks again!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using type=strings is fine. Would you be able to add a check to the Lektor build process so that there's an error if there's a missing category page?

Feel free to make another PR; I don't have an opinion either way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgodey One way to add a check to the Lektor build is to build a custom plugin. It will live under packages/ directory(which is not present currently).
I have made a simple plugin to inject a function check_file(filename) into template globals which can be used to raise an error if the corresponding categories do not exist. Same can be done in implementing authors if needed.
Shall I continue this way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that approach sounds good, thanks!

<p class="meta mt-0 mb-0"><span class="text-muted">Categories: </span>
{% if this.categories|length %}
{% for category in this.categories %}
<strong>{{ category }}</strong>{{ "," if not loop.last }}
<a href="/archives/blog-categories/{{blog_name + '/' + category }}">{{ category }}</a>{{ "," if not loop.last }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All blogs are not going to be under archives.

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

Successfully merging this pull request may close these issues.

Blog: Create category pages that show posts associated with a category.
2 participants