Closed tuvokki closed 5 years ago
It is certainly doable, but pelican
wasn't designed to be used as API. So, you'd need a controller script doing the hard work. I can give some pointers though.
All you need is pretty much an ArticlesGenerator
doing generate_context
with the right settings
. That should give you tags, categories etc.... It's probably obvious that this requires reading whole content, so doing this every time you run might not be feasible. You might want to read once and cache values in a JSON or such. And possibly refresh based on a command occasionally.
With help of your comment and some debugging I came up with a result, based on the loc_context
which is a trial-and-error bogus variable since it does not seem to be used in my use-case.
It needs some polishing. 😁
This snippet seems to produce the desired results:
from pelican import ArticlesGenerator, settings
loc_context = {
'generated_content': {'location': ''},
'static_links': set(),
'NEWEST_FIRST_ARCHIVES': True
}
@task
def yolo(c):
loc_settings = settings.read_settings(path=os.path.join('.', 'pelicanconf.py'))
gen = ArticlesGenerator(loc_context, loc_settings, 'content', 'themes', 'output')
gen.generate_context()
print(gen.tags.keys())
@tuvokki: Glad to hear you found a solution. ✨
Hi, like in issue #1410 I have been working on something similar, based on PyInquirer to gather data for article generation. For this I would like to have a list of categories and tags so I can present the user with a nice list of options that are already in the content. Is there a way to ask pelican for this data? Something like:
Which I can use to populate a list of options (see: list.py example)
Btw. it can be a use-case for #2539 When using tasks.py the pelican-api could be used to do this: