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

Ability to prerender to about.html instead of about/index.html like Sapper #1443

Closed
bdadam opened this issue May 13, 2021 · 10 comments · Fixed by #2632
Closed

Ability to prerender to about.html instead of about/index.html like Sapper #1443

bdadam opened this issue May 13, 2021 · 10 comments · Fixed by #2632
Labels
feature request New feature or request p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-static
Milestone

Comments

@bdadam
Copy link

bdadam commented May 13, 2021

Describe the bug
When setting tralilingSlash: 'ignore' then the static adapter generates wrong files, e.g.

  • blog/hello-world.html.svelte is generated as blog/hello-world.html/index.html
  • about.svelte is generated as about/index.html

To Reproduce
Here is a repo with issue reproduction, generated files are also pushed to the main branch in dist directory: https://github.com/bdadam/svelte-kit-static-issue

The repo was freshly created with npm init svelte@next ..

Expected behavior

  • blog/hello-world.html.svelte => blog/hello-world.html.html
  • about.svelte is generated as about.html

Information about your SvelteKit Installation:

  • The repo was freshly created with npm init svelte@next .
  • yarn add -D @sveltejs/adapter-node@next to install the static adapter

Severity
For me this is a blocker in adopting Svelte Kit for one side project. I have a website which has 6+ years old URLs with .html extensions, e.g. https://example.com/blog/hello-world.html. I don't want to touch these URLs due to all the SEO rank and backlinks they received throughout the years. In all honesty this is a toy project - but I guess I'm not alone with this requirement.

@babichjacob
Copy link
Member

* `about.svelte` is generated as `about/index.html`

This is correct / intended: https://kit.svelte.dev/docs#ssr-and-javascript-prerender-route-conflicts

* `blog/hello-world.html.svelte` is generated as `blog/hello-world.html/index.html`

This is (possibly?) not.

@babichjacob babichjacob added bug Something isn't working pkg:adapter-static labels May 13, 2021
@bdadam
Copy link
Author

bdadam commented May 13, 2021

Is there really no way to get about.html to be generated from about.svelte?

@Conduitry Conduitry added feature request New feature or request and removed bug Something isn't working labels May 13, 2021
@Conduitry
Copy link
Member

Conduitry commented May 13, 2021

A recent-ish new feature in Sapper was to have foo.html.svelte render to foo.html when exporting a static site (rather than foo.html/index.html), but apparently that didn't make its way into SvelteKit. I think that would be a reasonable enhancement.

In any case, about.svelte should never generate about.html, as they correspond to different routes (/about vs /about.html).

@benmccann benmccann changed the title Static adapter generates wrong files when tralilingSlash: 'ignore' is used Pre-rendering .html.svelte source does not create .html files like Sapper May 13, 2021
@benmccann benmccann added this to the 1.0 milestone May 13, 2021
@honai
Copy link

honai commented Jul 17, 2021

Hi, I also want to create non-indexed HTML file and I found this issue.

It would be useful if we could use a route which ends with .html , especially for custom 404 page for some platforms (See Additional Information of my comment ).

I made PR for this: #1939

@benmccann benmccann added the p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. label Aug 4, 2021
@benmccann benmccann changed the title Pre-rendering .html.svelte source does not create .html files like Sapper Ability to prerender to about.html instead of about/index.html like Sapper Aug 12, 2021
@benmccann
Copy link
Member

benmccann commented Aug 12, 2021

Rich suggested he'd like to see this done in SvelteKit with a new boolean option rather than by renaming the file extension. I've closed the associated PR given that, but if anyone would like to take a stab at it with the new direction I'd be happy to take a look

bfanger pushed a commit to bfanger/kit that referenced this issue Oct 18, 2021
Usage:
```json
kit: {
    prerender: {
      subfolders: false,
    },
```
Setting the kit.prerender.subfolders setting to false (default is true) will change the filename generation from "/about/index.html" to "/about.html"

Inspiration for the `subfolders` name came from nuxt:
https://nuxtjs.org/docs/configuration-glossary/configuration-generate/#subfolders

- Fixes sveltejs#1443,
- Related to sveltejs#2276, [sapper/sveltejs#1021](sveltejs/sapper#1021)
bfanger pushed a commit to bfanger/kit that referenced this issue Oct 18, 2021
- Fixes sveltejs#1443

Setting the kit.prerender.subfolders to false (default is true) will change the filename generation from "/about/index.html" to "/about.html"
bfanger pushed a commit to bfanger/kit that referenced this issue Oct 18, 2021
- Fixes sveltejs#1443

Setting the kit.prerender.subfolders to false (default is true) will change the filename generation from "/about/index.html" to "/about.html"
bfanger pushed a commit to bfanger/kit that referenced this issue Oct 18, 2021
- Fixes sveltejs#1443

Setting the kit.prerender.subfolders to false (default is true) will change the filename generation from "/about/index.html" to "/about.html"
bfanger pushed a commit to bfanger/kit that referenced this issue Oct 18, 2021
- Fixes sveltejs#1443

Setting the kit.prerender.subfolders to false (default is true) will change the filename generation from "/about/index.html" to "/about.html"
@benblazak
Copy link
Contributor

Rich suggested he'd like to see this done in SvelteKit with a new boolean option rather than by renaming the file extension.

out of curiosity, did Rich mean a boolean option in each file, or a global one in svelte.config.js?


in the mean time, using the file extension to indicate output turned out not to be too hard to write as a postbuild script

i added "postbuild": "scripts/dot-html.bash build", to the scripts section of package.json and in the scripts folder i have

#! /usr/bin/env bash

# move *.html/index.html to *.html in $build

build="$1"

err=0

for dir in $(find "$build" -path '*.html/index.html')
do
    parent="$(dirname $dir)"
    num=$(ls "$parent" | wc -l)
    if (( num != 1 ))
    then
        (( err++ ))
        echo warning: expected exactly one file: skipping \"$parent\"
        continue
    fi
    mv "$dir" "$parent.temp"
    rm -r "$parent"
    mv "$parent.temp" "$parent"
done

exit $err

bfanger pushed a commit to bfanger/kit that referenced this issue Jan 16, 2022
- Fixes sveltejs#1443

Setting the kit.prerender.subfolders to false (default is true) will change the filename generation from "/about/index.html" to "/about.html"
@bfanger
Copy link
Contributor

bfanger commented Jan 16, 2022

I've rebased PR 2632, any feedback that prevents merging this PR would be appreciated.

Rich-Harris added a commit that referenced this issue Jan 29, 2022
* [feat] add prerender.subfolders setting

- Fixes #1443

Setting the kit.prerender.subfolders to false (default is true) will change the filename generation from "/about/index.html" to "/about.html"

* remove separate prerender tests in favour of the new test suite

* on second thoughts, save that for a follow-up PR

* remove unused file

* rename prerender.subfolders to prerender.createIndexFiles

Co-authored-by: Bob Fanger <b.fanger@wearetriple.com>
Co-authored-by: Rich Harris <hello@rich-harris.dev>
@bfanger
Copy link
Contributor

bfanger commented Jan 29, 2022

In @sveltejs/kit version 1.0.0-next.265 and up you'll be able to use the trailingSlash setting.
(The new default is to render about.html).

trailingSlash If trailingSlash is always, a route like /about will result in an about/index.html file, otherwise it will create about.html, mirroring static webserver conventions.

@archoda
Copy link

archoda commented Mar 22, 2022

Is this fixed? I am the bellow packages with trailingSlash: true but still gettting 'example.html' instead of '/example/index.html'

 "@sveltejs/adapter-static": "^1.0.0-next.28",
 "@sveltejs/kit": "^1.0.0-next.265",
kit: {
    adapter: adapter(),
    serviceWorker: {
      files: () => {
        return ['static/lib', 'src/lib']
      }
    }
  },
  prerender: {
    default: true
  },
  trailingSlash: 'always',

@babichjacob
Copy link
Member

@archoda Upgrade your packages to their latest versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-static
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants