Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Oct 19, 2023
2 parents 63c5903 + 161ee12 commit c798f4b
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 81 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ Any BREAKING CHANGE between minor versions will be documented here in upper case
## [1.19.2] - Unreleased
### Added
- The second argument of the `page.data.url()` function has the default URL value.
- Default options for `Server` class:
- root: `Deno.cwd() + "/_site"`
- port: `8000`

### Changed
- Removed schema.org meta tags in metas plugin, because they are are not valid.
Probably it needs a new specific plugin.
- Updated the minimum Deno version supported to `1.37.2`.
- `redirects` `www` middleware support `307`, `308` status code.

### Fixed
- Ignore error checking Lume version in offline environments [#496].
- Updated dependencies: `deno_dom`, `katex`, `preact`, `sass`, `svg2png`, `terser`.
- `lightningcss` plugin: after refreshing changes the imports of all files are mixed.
- Updated dependencies: `std`, `deno_dom`, `katex`, `preact`, `sass`, `svg2png`, `terser`, `pagefind`.

## [1.19.1] - 2023-09-29
### Added
Expand Down
9 changes: 7 additions & 2 deletions core/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface Options {
port: number;
}

export const defaults: Options = {
root: `${Deno.cwd()}/_site`,
port: 8000,
};

export type RequestHandler = (req: Request) => Promise<Response>;
export type Middleware = (
req: Request,
Expand Down Expand Up @@ -47,8 +52,8 @@ export default class Server {
middlewares: Middleware[] = [];
#server?: HttpServer;

constructor(options: Options) {
this.options = options;
constructor(options: Partial<Options> = {}) {
this.options = { ...defaults, ...options };
}

/** Register one or more middlewares */
Expand Down
2 changes: 1 addition & 1 deletion core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const pluginNames = [

/** Check the compatibility with the current Deno version */
export function checkDenoVersion(): void {
const minimum = "1.33.4";
const minimum = "1.37.2";
const current = Deno.version.deno;

if (current < minimum) {
Expand Down
2 changes: 1 addition & 1 deletion deps/assert.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/assert/mod.ts";
export * from "https://deno.land/std@0.204.0/assert/mod.ts";
2 changes: 1 addition & 1 deletion deps/base64.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/encoding/base64.ts";
export * from "https://deno.land/std@0.204.0/encoding/base64.ts";
2 changes: 1 addition & 1 deletion deps/colors.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/fmt/colors.ts";
export * from "https://deno.land/std@0.204.0/fmt/colors.ts";
2 changes: 1 addition & 1 deletion deps/crypto.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/crypto/mod.ts";
export * from "https://deno.land/std@0.204.0/crypto/mod.ts";
2 changes: 1 addition & 1 deletion deps/flags.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/flags/mod.ts";
export * from "https://deno.land/std@0.204.0/flags/mod.ts";
2 changes: 1 addition & 1 deletion deps/front_matter.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/front_matter/any.ts";
export * from "https://deno.land/std@0.204.0/front_matter/any.ts";
2 changes: 1 addition & 1 deletion deps/fs.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/fs/mod.ts";
export * from "https://deno.land/std@0.204.0/fs/mod.ts";
2 changes: 1 addition & 1 deletion deps/hex.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/encoding/hex.ts";
export * from "https://deno.land/std@0.204.0/encoding/hex.ts";
6 changes: 3 additions & 3 deletions deps/http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { serveFile } from "https://deno.land/std@0.203.0/http/file_server.ts";
export { Server } from "https://deno.land/std@0.203.0/http/server.ts";
export { serveFile } from "https://deno.land/std@0.204.0/http/file_server.ts";
export { Server } from "https://deno.land/std@0.204.0/http/server.ts";

export type { ConnInfo } from "https://deno.land/std@0.203.0/http/server.ts";
export type { ConnInfo } from "https://deno.land/std@0.204.0/http/server.ts";
2 changes: 1 addition & 1 deletion deps/jsonc.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/jsonc/mod.ts";
export * from "https://deno.land/std@0.204.0/jsonc/mod.ts";
2 changes: 1 addition & 1 deletion deps/media_types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/media_types/mod.ts";
export * from "https://deno.land/std@0.204.0/media_types/mod.ts";
2 changes: 1 addition & 1 deletion deps/pagefind.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "npm:[email protected].3";
export * from "npm:[email protected].4-beta.0";
3 changes: 2 additions & 1 deletion deps/path.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "https://deno.land/[email protected]/path/mod.ts";
export * from "https://deno.land/[email protected]/path/mod.ts";
export * as posix from "https://deno.land/[email protected]/path/posix/mod.ts";
2 changes: 1 addition & 1 deletion deps/sass.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "npm:[email protected].0";
export * from "npm:[email protected].3";
2 changes: 1 addition & 1 deletion deps/snapshot.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/testing/snapshot.ts";
export * from "https://deno.land/std@0.204.0/testing/snapshot.ts";
2 changes: 1 addition & 1 deletion deps/toml.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/toml/mod.ts";
export * from "https://deno.land/std@0.204.0/toml/mod.ts";
2 changes: 1 addition & 1 deletion deps/xml.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/[email protected].1/mod.ts";
export * from "https://deno.land/x/[email protected].2/mod.ts";
2 changes: 1 addition & 1 deletion deps/yaml.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.203.0/yaml/mod.ts";
export * from "https://deno.land/std@0.204.0/yaml/mod.ts";
4 changes: 3 additions & 1 deletion middlewares/redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Options {

export interface Redirect {
to: string;
code: 301 | 302 | 200;
code: 301 | 302 | 307 | 308 | 200;
}

/** Implements redirects */
Expand All @@ -28,6 +28,8 @@ export default function redirects(options: Options): Middleware {
switch (redirect.code) {
case 301:
case 302:
case 307:
case 308:
return new Response(null, {
status: redirect.code,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion middlewares/www.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Middleware } from "../core.ts";

export interface Options {
add: boolean;
code: 301 | 302;
code: 301 | 302 | 307 | 308;
}

export const defaults: Options = {
Expand Down
101 changes: 53 additions & 48 deletions plugins/lightningcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function (userOptions?: DeepPartial<Options>) {
site.loadAssets(options.extensions);

if (options.includes) {
site.process(options.extensions, lightningCSSBundler);
site.processAll(options.extensions, lightningCSSBundler);
} else {
site.process(options.extensions, lightningCSSTransformer);
}
Expand Down Expand Up @@ -91,54 +91,59 @@ export default function (userOptions?: DeepPartial<Options>) {
);
}

async function lightningCSSBundler(file: Page) {
const { content, filename, sourceMap, enableSourceMap } = prepareAsset(
site,
file,
);

// Process the code with lightningCSS
const bundleOptions: BundleAsyncOptions<CustomAtRules> = {
filename,
sourceMap: enableSourceMap,
inputSourceMap: JSON.stringify(sourceMap),
...options.options,
resolver: {
resolve(id: string, from: string) {
return resolveInclude(
id,
options.includes as string,
posix.dirname(from),
);
},
async read(file: string) {
if (file === filename) {
return content;
}

if (file.startsWith("http")) {
return read(file, false, {
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0",
},
});
}

return await site.getContent(file, textLoader) as string;
/**
* Bundles all CSS files into a single file
* This cannot be done in parallel because ligthningcss has a bug that mixes the imports of all files
* Seems like executing the bundler in sequence fixes the issue
*/
async function lightningCSSBundler(files: Page[]) {
for (const file of files) {
const { content, filename, sourceMap, enableSourceMap } = prepareAsset(
site,
file,
);

const { includes } = site.options;

// Process the code with lightningCSS
const bundleOptions: BundleAsyncOptions<CustomAtRules> = {
filename,
sourceMap: enableSourceMap,
inputSourceMap: JSON.stringify(sourceMap),
...options.options,
resolver: {
resolve(id: string, from: string) {
return resolveInclude(id, includes, posix.dirname(from));
},
async read(file: string) {
if (file === filename) {
return content;
}

if (file.startsWith("http")) {
return read(file, false, {
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0",
},
});
}

return await site.getContent(file, textLoader) as string;
},
},
},
};

const result = await bundleAsync(bundleOptions);
const decoder = new TextDecoder();

saveAsset(
site,
file,
decoder.decode(result.code),
enableSourceMap ? decoder.decode(result.map!) : undefined,
);
};

const result = await bundleAsync(bundleOptions);
const decoder = new TextDecoder();

saveAsset(
site,
file,
decoder.decode(result.code),
enableSourceMap ? decoder.decode(result.map!) : undefined,
);
}
}
};
}
Expand Down
14 changes: 7 additions & 7 deletions tests/__snapshots__/pagefind.test.ts.snap

Large diffs are not rendered by default.

0 comments on commit c798f4b

Please sign in to comment.