Skip to content

Commit

Permalink
allow case sensitive urls #625
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Jun 27, 2024
1 parent 3a2988e commit f705c16
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions core/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const defaults: SiteOptions = {
src: "./",
dest: "./_site",
emptyDest: true,
caseSensitiveUrls: false,
includes: "_includes",
location: new URL("http://localhost"),
prettyUrls: true,
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -176,7 +178,7 @@ export default class Site {
// Other stuff
const events = new Events<SiteEvent>();
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({
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion core/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Page, StaticFile } from "./file.ts";

export interface Options {
dest: string;
caseSensitiveUrls: boolean;
}

/** Generic interface for Writer */
Expand All @@ -25,12 +26,14 @@ export interface Writer {
*/
export class FSWriter implements Writer {
dest: string;
caseSensitiveUrls: boolean;

#outputs = new Map<string, [number, string, string]>();
#saveCount = 0;

constructor(options: Options) {
this.dest = options.dest;
this.caseSensitiveUrls = options.caseSensitiveUrls;
}

/**
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion tests/assets/resolve_urls/statics/asset.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This file is copied statically.
This file is copied statically.

0 comments on commit f705c16

Please sign in to comment.