Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to keep pages with .html suffix in eleventy output? #913

Closed
ursbraem opened this issue Feb 7, 2020 · 11 comments
Closed

How to keep pages with .html suffix in eleventy output? #913

ursbraem opened this issue Feb 7, 2020 · 11 comments

Comments

@ursbraem
Copy link

ursbraem commented Feb 7, 2020

Hi!
I have an existing oldschool, pure html static site I want to retrofit with an SSG, and I chose eleventy and had a cool experience until now. But here's my first doubt:

The site's structure is as such:

+ index.html
+ somepage.html
+ otherpage.html

As described on https://www.11ty.dev/docs/permalinks/#cool-uris-dont-change, eleventy will create:

+ index.html
+ somepage/index.html
+ otherpage/index.html

But I don't want to change the (un)cool URIs I already have :-)
I understand I can add a .htaccess rewrite on the server to rewrite the URLs.

But isn't it possible to configure eleventy so it keeps the exact structure of the old site? I'd think so, but didn't find it in the docs yet.

PS: I posted the same question on SO https://stackoverflow.com/q/60119279/160968 but then I noticed that the github issues here might be the better place to ask.

@pdehaan
Copy link
Contributor

pdehaan commented Feb 7, 2020

You can set the permalink value for the desired output files in your front matter:

permalink: somepage.html

Or, depending on your config, you might be able to use permalink: "{{page.fileSlug}}.html"

@ursbraem
Copy link
Author

ursbraem commented Feb 8, 2020

@pdehaan Thanks!

I'd rather not add a front matter to each page. Is there such a setting for config?
Something like [pseudocode:] eleventyConfig.permalink("{{page.fileSlug}}.html");

@pdehaan
Copy link
Contributor

pdehaan commented Feb 8, 2020

@ursbraem It's tricky to say without seeing your code.
The best docs are at https://www.11ty.dev/docs/permalinks/

I have a few examples of dynamic permalinks in my GitHub repos, but probably nothing minimal. I can try putting something together, but it can sometimes be very specific to your folder structure. For example, I'll often use some src/pages/pages.11tydata.json file in my src/pages/ folder to set dynamic permalinks for all files in a folder instead of setting it on each template individually. https://www.11ty.dev/docs/data-template-dir/

@pdehaan
Copy link
Contributor

pdehaan commented Feb 8, 2020

Basic proof of concept at https://github.com/pdehaan/11ty-dynamic-permalink-test which shows using a "src/pages/pages.11tydata.json" file to set permalink structure for an entire directory of templates instead of needing to set it individually in each file's front matter.

@ursbraem
Copy link
Author

ursbraem commented Feb 8, 2020

This works flawlessly, thanks!

@ursbraem ursbraem closed this as completed Feb 8, 2020
@ursbraem
Copy link
Author

ursbraem commented Feb 8, 2020

Interesting too

@ursbraem
Copy link
Author

ursbraem commented Feb 9, 2020

ps @pdehaan I've added the solution to my stackoverflow question. If you want to add it from your side, please do so, I'll accept it then

@Rangoli-Software
Copy link

I am unable to get the vanilla permalink to work, even with the YAML method. I'm using the latest 0.10 version of 11ty.

@pdehaan
Copy link
Contributor

pdehaan commented Feb 9, 2020

@Rangoli-Software can you post your template’s front matter of the permalink that isn’t working and I can take a look.

@Rangoli-Software
Copy link

I went back to what I was using before with EJS (which is a hack, but it works).

permalink: "<%- page.inputPath.substring(1) %>"

so I'm not actively looking to get this to work any more.

@dd-pardal
Copy link

Basic proof of concept at https://github.com/pdehaan/11ty-dynamic-permalink-test [...]

If anyone reading this needs to keep the .html extension and also the path to the file, replace page.fileSlug to page.filePathStem in src/pages/pages.11tydata.json.

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

No branches or pull requests

4 participants