diff --git a/CHANGELOG.md b/CHANGELOG.md index aa49d003..d87dcd77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project try to adheres to [Semantic Versioning](https://semver.org/). Go to the `v1` branch to see the changelog of Lume 1. ## [2.2.3] - Unreleased +### Added +- New option `caseSensitiveUrls` to allow to export two urls with the same name but different cases [#625]. + ### Fixed - Updated dependencies: `std`. @@ -420,6 +423,7 @@ Go to the `v1` branch to see the changelog of Lume 1. [#617]: https://github.com/lumeland/lume/issues/617 [#618]: https://github.com/lumeland/lume/issues/618 [#619]: https://github.com/lumeland/lume/issues/619 +[#625]: https://github.com/lumeland/lume/issues/625 [2.2.3]: https://github.com/lumeland/lume/compare/v2.2.2...HEAD [2.2.2]: https://github.com/lumeland/lume/compare/v2.2.1...v2.2.2 diff --git a/core/site.ts b/core/site.ts index 4831870f..b6ac5df4 100644 --- a/core/site.ts +++ b/core/site.ts @@ -42,6 +42,7 @@ const defaults: SiteOptions = { src: "./", dest: "./_site", emptyDest: true, + caseSensitiveUrls: false, includes: "_includes", location: new URL("http://localhost"), prettyUrls: true, @@ -141,7 +142,8 @@ export default class Site { const src = this.src(); const dest = this.dest(); - const { includes, cwd, prettyUrls, components, server } = this.options; + const { includes, cwd, prettyUrls, components, server, caseSensitiveUrls } = + this.options; // To load source files const fs = new FS({ root: src }); @@ -176,7 +178,7 @@ export default class Site { // Other stuff const events = new Events(); const scripts = new Scripts({ cwd }); - const writer = new FSWriter({ dest }); + const writer = new FSWriter({ dest, caseSensitiveUrls }); const url404 = server.page404 ? normalizePath(server.page404) : undefined; const searcher = new Searcher({ @@ -915,6 +917,9 @@ export interface SiteOptions { /** Set true to generate pretty urls (`/about-me/`) */ prettyUrls: boolean; + /** Set true to don't consider two urls the equal if the only difference is the case */ + caseSensitiveUrls: boolean; + /** The local server options */ server: ServerOptions; diff --git a/core/writer.ts b/core/writer.ts index 5f78d0a3..e6065035 100644 --- a/core/writer.ts +++ b/core/writer.ts @@ -9,6 +9,7 @@ import type { Page, StaticFile } from "./file.ts"; export interface Options { dest: string; + caseSensitiveUrls: boolean; } /** Generic interface for Writer */ @@ -25,12 +26,14 @@ export interface Writer { */ export class FSWriter implements Writer { dest: string; + caseSensitiveUrls: boolean; #outputs = new Map(); #saveCount = 0; constructor(options: Options) { this.dest = options.dest; + this.caseSensitiveUrls = options.caseSensitiveUrls; } /** @@ -68,7 +71,7 @@ export class FSWriter implements Writer { } const filename = posix.join(this.dest, outputPath); - const id = filename.toLowerCase(); + const id = this.caseSensitiveUrls ? filename : filename.toLowerCase(); const hash = await sha1(content); const previous = this.#outputs.get(id); this.#outputs.set(id, [this.#saveCount, sourcePath, hash]); diff --git a/tests/assets/resolve_urls/statics/asset.md b/tests/assets/resolve_urls/statics/asset.md index 37ca9298..4d346e52 100644 --- a/tests/assets/resolve_urls/statics/asset.md +++ b/tests/assets/resolve_urls/statics/asset.md @@ -1 +1 @@ -This file is copied statically. \ No newline at end of file +This file is copied statically.