Tags Pages

49 views
Skip to first unread message

Merrick Christensen

unread,
Sep 15, 2012, 5:29:13 PM9/15/12
to doc...@googlegroups.com
Anyway to create multiple files from a single template? For example, query my documents for unique tags and create a tags page for each? E.G.:

// Some doc
['one', 'other-tag']

// A different doc
['one', 'nice']

Then generate three pages tags/one.html would contain both docs, other-tag.html would hold one. Etc. Just wondering how people are resolving this problem.

Thanks!

Benjamin Lupton

unread,
Sep 16, 2012, 7:18:10 PM9/16/12
to
Thanks for this, it's something that has been requested a bit - https://groups.google.com/forum/#!topic/docpad/WXVP4TAWheo - touches on it a bit more.

It is definitely something nice to have, though I haven't figured out the "how to do it" yet.

One way would be to pragmatically do it via an event inside the docpad configuration file. So cycle through all the tags, and with them, create a document that uses this layout. That would solve this use case.

The problem with the above use case, is that it is very counter-intuitive, or at least not as intuitive as a mere dynamic document which would only take a few minutes to do. However, dynamic documents only work for node.js servers. Another solution is to write it as a dynamic document, then if they are doing a static generation, somehow convert it to a static implementation.

However, as soon as we start delving here, the complication VS value benefit tilts a lot. So my suggestion is to just use dynamic documents and host on a node.js server, rather than beating around the bush with accomplishing dynamic things with a static server that just wasn't built for such use cases.

Using dynamic documents for tagging would work like so:
1. Create a search.html.eco
2. Make it a dynamic document
3. Use it via urls like search.html?tag=blah
4. Do a query like:
<% if @req.query.tag: %>
<% for document in @getDocuments(tag: $has: req.query.tag).toJSON(): %>
...

That should put you on the right track. I can do up a working example of it using dynamic documents, but that will take some time.

Here is paging accomplished with a dynamic document for reference: https://gist.github.com/3695876

Cheers,
- Ben

Merrick Christensen

unread,
Sep 26, 2012, 1:16:05 AM9/26/12
to doc...@googlegroups.com
Thanks for the killer reply, honestly I disagree with the conclusion that one is over complicating things by trying to do dynamic things with a static server. Honestly, thats what this whole docpad project is about, after all it wasn't very long ago people considers <?php include('header.php'); ?> to be pretty uber dynamic behavior. There is nothing truly dynamic about tags in my opinion, they are a static content that have relationship to other static content fully controlled by the developer. Now search, that is very dynamic as it is controlled by a third party. Part of the whole pull to something like docpad is that I can have rigid technical restrictions on the server but have all the freedom of tooling on my local machine or build server. Ultimately, what I am trying to say is I am unsatisfied with the argument that tags ought to be relegated and considered as content that is dynamic and requires the restrictions that dynamic content requires, this simply isn't the case for lots of content that doesn't need a document representation.

I can understand the design goal and attraction to keeping docpad simple and straight forward (seriously congratulations on that), but I'm not so sure that this has to be counter intuitive. I wonder if docpad could offer a plugin API that has more intimate interaction with the generator using events and resolve functions. One example might be something that looks like this:


modules.exports = function(docpad) {

 
var tags = [];  

  docpad
.on('parse', function(document) {
    document
.metadata.tags.forEach(function(tag) {
     
if (~tags.indexOf(tag)) {
        tags
.push(tag);
     
}
    });
 
});

  docpad
.on('complete', function() {
    tags
.forEach(function(tag) {
      docpad
.generate('tags/'+tag, 'tag-layout.eco.html', {
        data
: docpad.findAllDocs({ tag: tag });
      });
   
});
 
});

 
});

};

Please forgive that these APIs are entirely made up, I simply laid out this page as pseudo code to explain the concept. The configuration file can remain configuration and you can relegate some of this complicated stuff to a plugin system (like you so beautiful already have in a lot of other areas.) Having this kind of integration ability with docpad would provide some major wins, like the ability to alter content in the parsing stage beyond that of a template language. 

Hopefully this makes sense, thanks for the absolutely killer project. Docpad has been awesome to work with thus far.

What are your thoughts?

Merrick - @iammerrick

After Thought: How does nanoc allow you to do tags, if at all?






On Sunday, September 16, 2012 5:16:30 PM UTC-6, Benjamin Lupton wrote:
Thanks for this, it's something that has been requested a bit - https://groups.google.com/forum/#!topic/docpad/WXVP4TAWheo - touches on it a bit more.

It is definitely something nice to have, though I haven't figured out the "how to do it" yet.

One way would be to pragmatically do it via an event inside the docpad configuration file. So cycle through all the tags, and with them, create a document that uses this layout. That would solve this use case.

The problem with the above use case, is that it is very counter-intuitive, or at least not as intuitive as a mere dynamic document which would only take a few minutes to do. However, dynamic documents only work for node.js servers. Another solution is to write it as a dynamic document, then if they are doing a static generation, somehow convert it to a static implementation.

However, as soon as we start delving here, the complication VS value benefit tilts a lot. So my suggestion is to just use dynamic documents and host on a node.js server, rather than beating around the bush with accomplishing dynamic things with a static server that just wasn't built for such use cases.

Using dynamic documents for tagging would work like so:
1. Create a search.html.eco
2. Make it a dynamic document
3. Use it via urls like search.html?tag=blah
4. Do a query like:
<% if @req.query.tag: %>
<% for document in @getDocuments(tag: $has: req.query.tag).toJSON(): %>
...

That should put you on the right track. I can do up a working example of it using dynamic documents, but that will take some time.

Here is paging accomplished with a dynamic document for reference: https://gist.github.com/3695876

Cheers,
- Ben


On Sunday, 16 September 2012 07:29:13 UTC+10, Merrick Christensen wrote:

Benjamin Lupton

unread,
Sep 26, 2012, 2:17:43 AM9/26/12
to doc...@googlegroups.com
Interesting... I always like it when people refuse to take no for an answer!

Seeing your pseudo code and hearing your arguments, it got me thinking, perhaps we can spec out two plugins to accomplish the desired functionality in an intuitive easy way. They can be called meta2documents (for converting meta information from documents to documents to be rendered) and files2documents (for automatically documents to be rendered which are referenced to files like images etc).

Configurations would be:
1. What to look for
2. What file path convention should be used for writing the renderings to the out directory
3. What partial should be used as the base for the renderings


Example configuration for meta2documents:
1. tags
2. tags/{tag}.html
3. tag.html.eco


Example configuration for files2documents:

For gallery index page:
1. gallery/{gallery}
2. gallery/{gallery}/index.html
3. gallery.html.eco

For gallery images:
1. gallery/{gallery}/{image}
2. gallery/{gallery}/{image}.html
3. gallery-image.html.eco


Perhaps that could work? Really rough and just real quick, so no doubt may need to change. Though I think if we could develop a plugin to make this dirt simple, then the cost of doing it versus return value would then be justified.

Kelvin Luck

unread,
Sep 26, 2012, 3:53:05 AM9/26/12
to doc...@googlegroups.com
I'd definitely be interested in a feature like this for "static dynamic" pages - tags / category pages are an obvious example (which I was already looking for a way to do) but I'm sure it would also have lots of uses beyond this...

Cheers,

Kelvin :)

--
You received this message because you are subscribed to the Google Groups "DocPad" group.
To post to this group, send email to doc...@googlegroups.com.
To unsubscribe from this group, send email to docpad+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/docpad/-/tXXZBcCZ-rAJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Benjamin Lupton

unread,
Aug 7, 2013, 12:18:22 AM8/7/13
to doc...@googlegroups.com
This is now possible with the importers functionality - https://github.com/bevry/docpad/issues/500

Using that new functionality we've created a tags plugin - https://github.com/docpad/docpad-plugin-tags - that generates tag pages for us automatically.
Reply all
Reply to author
Forward
0 new messages