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

access /foo and get /foo.html #193

Closed
kuboon opened this issue Apr 28, 2022 · 2 comments
Closed

access /foo and get /foo.html #193

kuboon opened this issue Apr 28, 2022 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@kuboon
Copy link
Contributor

kuboon commented Apr 28, 2022

Github pages can access foo.html by url /foo
see https://rsp.github.io/gh-pages-no-extension/test1

I want lume server to work the same way.

currently this is my solution:

// config.ts
import { Middleware } from "lume/core.ts";

const github_pages: Middleware = async (req, next) => {
  const response = await next(req);
  if(response.status !== 404) {
    return response;
  }
  const req2 = new Request(req.url + ".html", req);
  return next(req2);
}

const site = lume({
  dest: './docs',
  prettyUrls: false,
  server: {
    middlewares: [github_pages],
  }
});

It would be smarter if lume had a server option and could scan resources in core/server.ts

@oscarotero
Copy link
Member

This requires also some changes in the way the page url variable is builded.

lume/core/filesystem.ts

Lines 218 to 223 in bc8412d

updateUrl() {
this.data.url =
(this.dest.ext === ".html" && posix.basename(this.dest.path) === "index")
? this.dest.path.slice(0, -5)
: this.dest.path + this.dest.ext;
}

I think it's good idea but need to think the best way to implement it.

@oscarotero oscarotero added the enhancement New feature or request label Apr 28, 2022
oscarotero added a commit that referenced this issue May 12, 2022
@oscarotero oscarotero added this to the 1.9.0 milestone May 12, 2022
@oscarotero
Copy link
Member

I've implemented another option for prettyUrls to omit the .html extension but without saving the files as /index.html. It can be enabled with:

const site = lume({
  prettyUrls: "no-html-extension",
});

and will be available in Lume 1.9.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants