-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
Conversation
hidden = yes | ||
|
||
[children] | ||
replaced_with = site.query('archives/' + this.parent.path.split('/')[-1]).filter(F.categories.contains(this)) |
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.
All blogs will not be under archives
.
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.
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 |
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.
Do these files need to be created manually whenever a new category is created? How do we ensure that that happens?
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.
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.
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.
@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
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.
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.
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.
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!
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.
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.
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.
@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?
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.
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 }} |
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.
All blogs are not going to be under archives
.
Fixes #54
Description
blog-categories
andblog-category
models and templates.categories.html
macro.archives/old-tech-blog/
and make file structure underblog-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](https://user-images.githubusercontent.com/34679965/55657152-f4237500-5816-11e9-97a7-9dccc09e7e92.png)
All Categories of old-tech-blog
![Screenshot from 2019-04-06 02-11-08](https://user-images.githubusercontent.com/34679965/55657156-f685cf00-5816-11e9-9333-61c068faaa7a.png)
Blog posts for Individual Category
![Screenshot from 2019-04-06 02-11-58](https://user-images.githubusercontent.com/34679965/55657166-fbe31980-5816-11e9-8fa6-6c902607786b.png)
Category links in the blog are working
![Screenshot from 2019-04-06 02-57-11](https://user-images.githubusercontent.com/34679965/55657420-c8ed5580-5817-11e9-9eb9-f8a5e6600cd0.png)
Checklist:
Update index.md
).master
branch of the repository.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.