antwarjs / antwar

A static site generator built with React and Webpack.
https://antwar.js.org/
MIT License
460 stars 35 forks source link

Allow post urls to be generated based on post metadata #4

Closed bebraw closed 9 years ago

bebraw commented 9 years ago

Example:

// basic
function basicUrlify(post) {
    return post.category + '/' + slugify(post.title);
}

// multiple urls per post
function multipleUrlify(post) {
    return [
       post.category + '/' + slugify(post.title),
       dateify(post.date) + '/' + slugify(post.title)
    ];
}

// redirect
function redirectUrlify(post) {
    var to = dateify(post.date) + '/' + slugify(post.title);

    return [
        {
            from: post.category + '/' + slugify(post.title),
            to: to,
        },
        to,
    ];
}

You would just have one of these mappings somewhere in the project configuration. The nice thing is that it's very flexible and you can do 1-1, N-1 type of mappings and even rerouting (last case).

eldh commented 9 years ago

Yes! Great idea!

eldh commented 9 years ago

I'll start with a basic example in the config.

eldh commented 9 years ago

Fixed in 180faf8.