Comments (2)
Hi. Lume needs the .html
extension in the filename to identify the page as HTML and run html-specific processors.
But it's possible to remove the trailing slashes doing the following:
- Disable the prettyUrls option so the files are saved as (
/example.html
instead of/example/index.html
). Lume server serves the/example.html
for/example
requests as fallback. - Use
modify_urls
plugin to remove the.html
extension of the links of your HTML code:
site.use(modifyUrls({
fn(url) {
return url.endsWith(".html")
? url.slice(0, -5)
: url;
}
});
This converts <a href="/example.html">
to <a href="/example">
.
For feed and sitemaps plugin, there's no way to modify the urls (maybe it could be a good feature). You can process the files after created. For example:
site.process([".xml"], (pages) => {
for (const page of pages) {
if (page.data.url === "/sitemap.xml") {
page.content = page.content.replaceAll(/href="([^"]+)\.html"/g, "href="$1");
}
}
});
from lume.
Thanks a lot for the prompt reply and your help on this.
I implemented your proposal and adapted it slightly (mostly using the afterBuild
to also get access to the rss.xml
file) and it works like a charm.
For anyone else looking, here's what I came up with (based on @oscarotero writeup above):
// _config.ts
import lume from "lume/mod.ts";
import feed from "lume/plugins/feed.ts";
import sitemap from "lume/plugins/sitemap.ts";
import modifyUrls from "lume/plugins/modify_urls.ts";
import { join } from "https://deno.land/[email protected]/path/mod.ts";
const RSS_FILE_NAME = "rss.xml";
const SITEMAP_FILE_NAME = "sitemap.xml";
const site = lume({
prettyUrls: false
});
site.ignore("README.md")
.use(sitemap())
.use(feed(
{
output: [`/${RSS_FILE_NAME}`],
query: "type=posts",
info: {
title: "=site.title",
description: "=site.description",
},
items: {
title: "=title",
description: "=excerpt",
},
},
))
.use(modifyUrls({
fn: (url) => normalizeUrl(url),
}))
site.addEventListener("afterBuild", (event) => {
event.pages.forEach(async (page) => {
if (
page.data.url.includes(SITEMAP_FILE_NAME) ||
page.data.url.includes(RSS_FILE_NAME)
) {
const filePath = join("_site", page.data.url);
let content = await Deno.readTextFile(filePath);
if (page.data.url.includes(SITEMAP_FILE_NAME)) {
content = content.replaceAll(
/(<loc>)(.+)(\.html)(<\/loc>)/g,
"$1$2$4",
);
} else if (page.data.url.includes(RSS_FILE_NAME)) {
content = content.replaceAll(
/(<link>)(.+)(\.html)(<\/link>)/g,
"$1$2$4",
);
content = content.replaceAll(
/(<guid.*>)(.+)(\.html)(<\/guid>)/g,
"$1$2$4",
);
}
await Deno.writeTextFile(filePath, content);
}
});
});
export function normalizeUrl(url: string) {
let result = url;
result = result.endsWith(".html") ? result.slice(0, -5) : result;
result = result.endsWith("index") ? result.replace("index", "") : result;
result = result.endsWith("/") ? result.slice(0, -1) : result;
return result;
}
export default site;
from lume.
Related Issues (20)
- Plugin Nav: Cannot access 'item' before initialization HOT 3
- Minify <style> CSS from UnoCSS, when using `cssFile: false` HOT 2
- Use local version of Decap CMS script instead of unpkg.com HOT 2
- Search plugin seems to be missing pages generated by the multilanguage plugin HOT 6
- .well-known support HOT 3
- Filter Pages plugin removes asset files (arguably unexpected -- documentation issue?) HOT 2
- page does not refresh when _components/XXX.tsx is modified HOT 6
- esbuild plugin: timeout after 10 second on `deno task build` HOT 6
- Question: how to support both rendering .html from a file and also copying the raw file HOT 1
- esbuild: `.ts` imports aren't transformed into `.js` HOT 4
- `deno task lume` fails directly after init HOT 2
- Add image support in feeds. HOT 1
- Can't loop through search.pages() using Liquid HOT 2
- Add support for author in the feed plugin
- Lume failse to build/serve with atypical Linux directory structure. HOT 6
- Better path naming convension HOT 8
- Lume serve: expected to respect ServerOptions for location HOT 2
- @std/log not found in registry-staging.deno.com HOT 2
- lume().copy() is a no-op when lume({src: "docs" }) is set HOT 4
- search.pages() return results is zero HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lume.