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

More categories plugin support #619

Open
wants to merge 6 commits into
base: next
Choose a base branch
from

Conversation

vokimon
Copy link

@vokimon vokimon commented Jun 7, 2020

Prerequisites

Recommended Steps

  • My patch adds a new feature, therefore I have also added a help article about it
  • My patch changes Elegant behavior, therefore I have updated the help article to reflect this change
  • My commits are signed

Description

This PR includes support for having multiple categories in an article by means of more-categories plugin and template changes in this PR.

Templates changes keep the behavior on deployments not using the plugin. Whenever the attribute article.categories (added by more-categories) is missing, it constructs single category list [article.category] and proceeds.

Fixes #618: Since i had to update the keyword meta tag properly, this PR also fixes that issue. I could send a specific PR to fix just that if accepting this PR takes longer or it is not accepted.

@talha131
Copy link
Member

talha131 commented Jun 7, 2020

Thank you @vokimon. I will review and merge the PR soon.

@vokimon vokimon force-pushed the more_categories_plugin_support branch from 9ec8ba5 to 2c3d84a Compare June 8, 2020 17:18
@vokimon
Copy link
Author

vokimon commented Jun 10, 2020

Thanks. I did some further changes required to pass all automatic checks. Waiting for your human review.

The invariant is: output should look identical if you just activate or desactivate more-categories plugin and they only look different when you define an article with multiple categories.

Regarding the keywords meta, i fixed my fix, by testing with and without the plugin and with and without tags, keywords, categories. I don't know whether the project has any kind of automated testing but it would be nice to automate those test cases.

@iranzo
Copy link
Member

iranzo commented Sep 21, 2021

Hi @vokimon , sorry for the delay.

I've tested it, but I couldn't get it to work (I even rebased against of top of next branch).

I've downloaded the more_categories plugin and tested both with category: tech, tips and with categories: tech, tips.

So I'm wondering that something might be missing with the actual status of pelican + Elegant.

Would you mind updating the PR (with rebase) so that I can attempt again testing it?

Thanks!

@iranzo
Copy link
Member

iranzo commented Sep 21, 2021

Traceback (most recent call last):
  File "/home/iranzo/.bin/pelican", line 8, in <module>
    sys.exit(main())
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/pelican/__init__.py", line 520, in main
    autoreload(args)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/pelican/__init__.py", line 444, in autoreload
    pelican.run()
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/pelican/__init__.py", line 125, in run
    p.generate_output(writer)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/pelican/generators.py", line 686, in generate_output
    self.generate_pages(writer)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/pelican/generators.py", line 595, in generate_pages
    self.generate_articles(write)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/pelican/generators.py", line 469, in generate_articles
    url=article.url, blog=True)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/pelican/writers.py", line 270, in write_file
    override_output)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/pelican/writers.py", line 202, in _write_file
    output = template.render(localcontext)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/iranzo/.local/venvs/pelican/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/home/iranzo/www/themes/elegant/templates/article.html", line 1, in top-level template code
    {% extends 'base.html' %}
  File "/home/iranzo/www/themes/elegant/templates/base.html", line 50, in top-level template code
    {% block meta_tags_in_head %}
  File "/home/iranzo/www/themes/elegant/templates/article.html", line 23, in block "meta_tags_in_head"
    ) | join(', ') }}" />
TypeError: can only concatenate list (not "str") to list

My traceback :-)

@iranzo iranzo force-pushed the more_categories_plugin_support branch from 732172f to bbe8f77 Compare September 21, 2021 18:27
@vokimon
Copy link
Author

vokimon commented Sep 27, 2021

One year and two months after the PR it's hard for me to recall the intent of the code, but taking a look at it i would say that categories wasn't to be a comma separated string but a yaml list.

categories:
- cat1
- cat2
- dog

I don't recall if at any point of the metadata reading, comma separated strings were turn into a list as well. In such case, it looks like it is not happening. All my personal uses of the extension use yaml lists.

@vokimon vokimon closed this Sep 27, 2021
@vokimon vokimon reopened this Sep 27, 2021
The `more_categories` plugin enables having more than
one category for a single article by separating them
with commas.
This commit comprises the required template changes
to display all related categories instead of just one.
The change is safe when the plugin is not used.
It changes the category list in the last article section
of the index and in the article page.
It also modifies the keyword meta, to use all categories.
This commit also fixes an unreported bug with the keyword meta:
when no keywords or tags are specified, pointless commas were
added at the beginning or the end.
Because keywords is not a list but a string with comma separated
values, every letter was separated. Instead, just take it as a
single item and lets append it as a single item, but if empty
append an empty list.

Also, for categories, when no category and no categories plugin
is found resulted in [None].
@vokimon vokimon force-pushed the more_categories_plugin_support branch from bbe8f77 to d45a5fe Compare September 27, 2021 16:41
@iranzo
Copy link
Member

iranzo commented Sep 27, 2021

Hi,
With:

image

I'm still getting the traceback:

image

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

Successfully merging this pull request may close these issues.

3 participants