toastdotdev / toast

The best place to stack your JAM. Toast is a Jamstack framework
153 stars 13 forks source link

pages + directories are a little confusing #60

Closed jlengstorf closed 3 years ago

jlengstorf commented 3 years ago

using MDX, I have the following setup:

/
├── content/
│   └── blog/
│       └── some-post.mdx
└── src/
    └── pages/
        └── blog.js

the blog uses sourceMdx:

sourceMdx({
  setDataForSlug,
  directory: './content/blog',
  slugPrefix: '/blog',
})

if I run this, /blog ends up not working in the built site because the blog.js page is created as blog.html, which is overridden by the blog/ directory

the fix for this, I believe, is to generate blog/index.html instead of blog.html. functionally these should be equivalent, but it allows for defining a directory root

without this, I have to create src/pages/blog/index.js and the slug is wierd:

    setDataForSlug('/blog/index', {
      data: {
        posts,
      },
    })

this isn't the end of the world, but it's unintuitive

ChristopherBiscardi commented 3 years ago

if I run this, /blog ends up not working in the built site because the blog.js page is created as blog.html, which is overridden by the blog/ directory

I couldn't replicate "not working" here, could you be more specific about what behavior you're seeing and what http server you're using?

It works for me with this site and running npx serve public: https://github.com/ChristopherBiscardi/toast-blog-blog-index-repro/tree/ff671c7197bb4a112732b96922ae950216b4a4eb

I get this output, which serves me blog.html on /blog.

❯ ls -R public 
blog       index.html  styles.css
blog.html  src         web_modules

public/blog:
some-post.html  some-post.js  some-post.json
jlengstorf commented 3 years ago

hmm, looks like it's an http-server thing. my repro doesn't have this problem when I deploy to Netlify https://optimistic-curie-9bbe4e.netlify.app/blog