Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Reflect Content Structure in Routing Structure #124

Closed
skipjack opened this issue Apr 7, 2017 · 7 comments
Closed

Reflect Content Structure in Routing Structure #124

skipjack opened this issue Apr 7, 2017 · 7 comments

Comments

@skipjack
Copy link

skipjack commented Apr 7, 2017

Given the following antwar config:

//...
  '/': {
    title: 'webpack',
    path: function() {
        return require.context(
          'json-loader!yaml-frontmatter-loader!./content',
          false,
          /^\.\/.*\.md$/
        );
    },
    processPage: processPage(), 
    layouts: { 
      index: function() {
        return require('./components/splash/splash.jsx').default
      },
      page: function() {
        return require('./components/page/page.jsx').default
      }
    }
  }
// ...

and this content directory...

image

it would be great if antwar produced the routes and content in this manner:

/ - content from index.md
/another-page - content from another-page.md
/examples - content from examples/index.md
/examples/another-child - content from examples/another-child.md

... and so on, treating each directory as a new route with children and the index.md file as the content for the base route. Then within the section.all() data, these pages would be represented as:

[
  {
    title: 'webpack',
    url: '/',
    content: 'content from index.md...',
    pages: [
      { title: 'Another Page', url: '/another-page', content: 'content from another-page.md' },
      { title: 'Examples', url: '/examples', content: 'content from examples/index.md', pages: [
        { title: 'Another Child', url: '/examples/another-child', content: 'content from examples/another-child.md' }
      ]
    ]
  }
]

This way your content structure always reflects your directory structure and much less manual configuration is needed to lay out your project (especially if all files are markdown).

@bebraw
Copy link
Member

bebraw commented May 4, 2017

Maybe it would be possible to tie this together with the schema change discussed at #126.

@bebraw
Copy link
Member

bebraw commented May 17, 2017

I've been thinking about this. The most sensible option seems to be to implement this as an Antwar plugin like prevnext currently. The algorithm would have to go through the entire path definition and attach the information there. I imagine it's not needed for all sites so that's another reason why a plugin feels like the right direction.

@skipjack
Copy link
Author

The most sensible option seems to be to implement this as an Antwar plugin like prevnext currently.

Idk, a lot of other static site generators have this as the default behavior that can then be overridden (e.g. via the frontmatter in phenomic). Personally, I think this makes sense as it's more intuitive and easier to manage.

I imagine it's not needed for all sites so that's another reason why a plugin feels like the right direction.

I think there may be some instances where overrides are needed but I can't picture that many sites where this wouldn't be the desired base behavior for the majority of routes/content. I guess it's not a huge deal to have it as a plugin but I think supporting it by default would make more sense.

@bebraw
Copy link
Member

bebraw commented May 18, 2017

Ok. I guess I'll develop it as a plugin (easier to test etc.) and just enable the behavior by default. So it could become an opt-out if necessary.

@skipjack
Copy link
Author

That sounds good, I can't argue with it being modularized and if we find out I'm wrong then it'll be even easier to fix 😁.

@bebraw
Copy link
Member

bebraw commented Jul 28, 2017

There's something like this built-in now behind section.all(). I didn't pluginify the behavior just yet and the design can likely be improved. Better open separate issues for those based on need.

@bebraw bebraw closed this as completed Jul 28, 2017
@skipjack
Copy link
Author

Sure we can also discuss more in webpack/webpack.js.org#980... it seems the data, section.all() was the last thing (i.e. dynamic route generation seemed fine, just getting programmatic access to those routes was the problem). I've actually been doing some work on this for a separate project as in a webpack only solution that came out pretty nicely. Let's talk more on slack at some point...

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

No branches or pull requests

2 participants