Closed bebraw closed 7 years ago
A part of this can be implemented now via postProcess
hook. We still need some way to write custom pages (additional hook) before the plugin can be implemented in its entirety, though.
Can't we add pages in the postProcess hook? If we just allow the page the page to have a generic handler?
@eldh postProcess could work. Can we output files there? What would that generic handler look like? How would you define it?
Ah. We need to implement the postProcessPages hook.
Tag.jsx would use react-router.State mixin to get the tag and then fetch post data via PathsMixin.allPosts(). The postProcessPages fn would add one entry per tag, something like
{
url: tag/[tag],
handler: Tag.jsx,
title: [title],
tag: [tag]
}
Can you do that postProcessPages
bit and the changes needed? The whole process has to go there given we are converting post metadata to tag data that in turn is converted into pages. Here's the core algorithm:
// at postProcessPages before you generate tag paths
function gatherTags(posts) {
var tags = {};
posts.forEach(function(post) {
// check each post tag + adjust generated tags accordingly
// XXX: you might want to eliminate possible duplicates here before going
// through tags (ie. ['foo', 'bar', 'foo'])
post.tags.forEach(function(tag) {
if(tag in tags) {
tags[tag].push(post);
}
else {
tags[tag] = [post];
}
});
});
return tags;
}
Tag links per post might be able to rely on some convention like this:
<ul>{tags.map(function(tag) {
return <li><a href={'tags/' + tag}></a></li>;
})}</ul>
That in turn could be wrapped into <Tags data={post.tags} />
kind of helper and so on.
Yeah. I'll look into that when I finished extras/rss. We also need to think about how to theme these pages. Maybe make it possible for the theme to override the handler?
Maybe make it possible for the theme to override the handler?
Yeah. Ordering like plugin, theme, user would make sense.
You can attach tags to pages trivially now. There's also functionality that allows you to implement custom pages so I think we're set. No need to extend the core at least yet.
The tag plugin would operate based on posts tags metadata + provide a data source that can be used for routing. Ie. it would shape ['foo', 'bar'] into [{name: 'foo', url: '...', posts: [...]}, {name: 'bar', url: '...', posts: [...]}].
Example configuration