Skip to content

Commit

Permalink
chore: update fmt, vscode settings, run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jrson83 committed Jul 12, 2024
1 parent dc2706a commit 1d2b69b
Show file tree
Hide file tree
Showing 52 changed files with 931 additions and 929 deletions.
11 changes: 7 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit"
},
"files.insertFinalNewline": true,
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true,
"deno.config": "./deno.json",
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
"deno.suggest.imports.hosts": {
"https://deno.land": true,
"https://esm.sh": true
}
},
"editor.defaultFormatter": "denoland.vscode-deno"
}
22 changes: 11 additions & 11 deletions _build.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
type BuildMode = string | undefined;
type BuildMode = string | undefined

const createConfig = (mode: BuildMode) => {
if (typeof mode === "undefined") {
throw new Error("BUILD_MODE is not defined");
if (typeof mode === 'undefined') {
throw new Error('BUILD_MODE is not defined')
}
if (mode === "prod") {
if (mode === 'prod') {
return {
mode,
location: new URL("https://jrson.me"),
};
location: new URL('https://jrson.me'),
}
}
return {
mode,
location: new URL("http://localhost"),
};
};
location: new URL('http://localhost'),
}
}

const BUILD_MODE: BuildMode = Deno.env.get("BUILD_MODE");
const BUILD_MODE: BuildMode = Deno.env.get('BUILD_MODE')

export const config = createConfig(BUILD_MODE);
export const config = createConfig(BUILD_MODE)
56 changes: 28 additions & 28 deletions _config.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import { config } from "./_build.ts";
import { config } from './_build.ts'

import lume from "lume/mod.ts";
import date from "lume/plugins/date.ts";
import slugify_urls from "lume/plugins/slugify_urls.ts";
import jsx from "lume/plugins/jsx_preact.ts";
import sass from "lume/plugins/sass.ts";
import terser from "lume/plugins/terser.ts";
import inline from "lume/plugins/inline.ts";
import sitemap from "lume/plugins/sitemap.ts";
import unified from "lume/plugins/remark.ts";
import lume from 'lume/mod.ts'
import date from 'lume/plugins/date.ts'
import slugify_urls from 'lume/plugins/slugify_urls.ts'
import jsx from 'lume/plugins/jsx_preact.ts'
import sass from 'lume/plugins/sass.ts'
import terser from 'lume/plugins/terser.ts'
import inline from 'lume/plugins/inline.ts'
import sitemap from 'lume/plugins/sitemap.ts'
import unified from 'lume/plugins/remark.ts'

import remarkPlugins from "#plugins/unified/remark/mod.ts";
import rehypePlugins from "#plugins/unified/rehype/mod.ts";
import atomFeed from "#plugins/atom-feed/mod.ts";
import md5CacheBuster from "#plugins/md5-cache-buster/mod.ts";
import remarkPlugins from '#plugins/unified/remark/mod.ts'
import rehypePlugins from '#plugins/unified/rehype/mod.ts'
import atomFeed from '#plugins/atom-feed/mod.ts'
import md5CacheBuster from '#plugins/md5-cache-buster/mod.ts'

const site = lume({
location: config.location,
src: "./src",
src: './src',
server: {
page404: "/404/",
page404: '/404/',
},
}, {
url: {
names: {
url: "urlFilter",
htmlUrl: "htmlUrlFilter",
url: 'urlFilter',
htmlUrl: 'htmlUrlFilter',
},
},
});
})

site
.copy("assets", ".")
.copy('assets', '.')
.use(date())
.use(slugify_urls({
replace: {
"&": "and",
"@": "",
'&': 'and',
'@': '',
},
}))
.use(unified({
Expand All @@ -45,16 +45,16 @@ site
}))
.use(jsx())
.use(sass())
.loadAssets([".js"])
.loadAssets(['.js'])
.use(terser())
.use(inline())
.use(atomFeed())
.use(sitemap({
query: "indexable=true",
}));
query: 'indexable=true',
}))

if (config.mode === "prod") {
site.use(md5CacheBuster());
if (config.mode === 'prod') {
site.use(md5CacheBuster())
}

export default site;
export default site
2 changes: 2 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
}
},
"fmt": {
"semiColons": false,
"singleQuote": true,
"exclude": [
"./_site"
]
Expand Down
42 changes: 21 additions & 21 deletions plugins/_deprecated/sitemap/mod.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
// deno-lint-ignore-file -- The plugin is deprecated in favour of: https://lume.land/plugins/sitemap/

import { merge } from "lume/core/utils.ts";
import { Page } from "lume/core/filesystem.ts";
import { buildSort } from "lume/core/searcher.ts";
import { merge } from 'lume/core/utils.ts'
import { Page } from 'lume/core/filesystem.ts'
import { buildSort } from 'lume/core/searcher.ts'

import type { Site } from "lume/core.ts";
import type { Search } from "lume/plugins/search.ts";
import type { Site } from 'lume/core.ts'
import type { Search } from 'lume/plugins/search.ts'

export interface Options {
/** The query to search pages included in the sitemap */
query: string[];
query: string[]

/** The pages to exclude from the sitemap */
excludes: string[];
excludes: string[]

/** The values to sort the sitemap */
sort: string;
sort: string
}

// Default options
export const defaults: Options = {
query: [],
excludes: [],
sort: "url=asc",
};
sort: 'url=asc',
}

/** A plugin to generate a sitemap.xml from page files after build */
export default function (userOptions?: Partial<Options>): (site: Site) => void {
const options = merge(defaults, userOptions);
const options = merge(defaults, userOptions)

return (site: Site): void => {
site.addEventListener("afterRender", () => {
site.addEventListener('afterRender', () => {
// Create the sitemap.xml page
const sitemap: Page = Page.create("sitemap.xml", getSitemapContent(site));
const sitemap: Page = Page.create('sitemap.xml', getSitemapContent(site))

// Add to the sitemap page to pages
site.pages.push(sitemap);
});
site.pages.push(sitemap)
})

function getSitemapContent(site: Site): string {
// Get the search instance from the global data
const search = site.globalData.search as Search;
let sitemapPages = search.pages(options.query, options.sort) as Page[];
const search = site.globalData.search as Search
let sitemapPages = search.pages(options.query, options.sort) as Page[]

// Filter to remove `excludes` pages
if (Array.isArray(options.excludes) && options?.excludes?.length) {
sitemapPages = sitemapPages.filter((page) =>
!options.excludes.some((exclude) => page.dest.path.includes(exclude))
);
)
}

// Sort the pages
sitemapPages.sort(buildSort(options.sort));
sitemapPages.sort(buildSort(options.sort))

// deno-fmt-ignore
const sitemap: string = `
Expand All @@ -65,7 +65,7 @@ export default function (userOptions?: Partial<Options>): (site: Site) => void {
`}).join("").trim()}
</urlset>`.trim();

return `${sitemap}`;
return `${sitemap}`
}
};
}
}
2 changes: 1 addition & 1 deletion plugins/atom-feed/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as XMLFormat from "npm:[email protected]";
export * as XMLFormat from 'npm:[email protected]'
74 changes: 37 additions & 37 deletions plugins/atom-feed/mod.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
import { merge } from "lume/core/utils.ts";
import { Page } from "lume/core/filesystem.ts";
import { buildSort } from "lume/core/searcher.ts";
import { merge } from 'lume/core/utils.ts'
import { Page } from 'lume/core/filesystem.ts'
import { buildSort } from 'lume/core/searcher.ts'

import { isString } from "#utils";
import { isString } from '#utils'

import { XMLFormat } from "#plugins/atom-feed/deps.ts";
import { XMLFormat } from '#plugins/atom-feed/deps.ts'

import type { Site } from "lume/core.ts";
import type { Search } from "lume/plugins/search.ts";
import type { MetaData } from "lume/plugins/metas.ts";
import type { Site } from 'lume/core.ts'
import type { Search } from 'lume/plugins/search.ts'
import type { MetaData } from 'lume/plugins/metas.ts'

export interface Options {
/** The query to search pages included in the feed. defaults to `type=post` */
query: string[];
query: string[]

/** The values to sort the feeds pages. defaults to `date=desc` */
sort: string;
sort: string

/** The limit to display pages. defaults to `10` */
limit: number;
limit: number

/** Options passed to xml-formatter */
options: Partial<XMLFormat.XMLFormatterOptions>;
options: Partial<XMLFormat.XMLFormatterOptions>
}

// Default options
export const defaults: Options = {
query: ["type=post"],
sort: "date=desc",
query: ['type=post'],
sort: 'date=desc',
limit: 10,
options: {
indentation: " ",
indentation: ' ',
collapseContent: true,
lineSeparator: "\n",
lineSeparator: '\n',
},
};
}

export interface FeedMetaData extends MetaData {
author: {
name: string;
email: string;
url: string;
};
name: string
email: string
url: string
}
}

/** A plugin to <description> */
export default function (userOptions?: Partial<Options>) {
const options = merge(defaults, userOptions);
const options = merge(defaults, userOptions)

return (site: Site) => {
site.addEventListener("afterRender", () => {
site.addEventListener('afterRender', () => {
// Create the sitemap.xml page
const feed = Page.create("feed.xml", getFeedContent(site));
const feed = Page.create('feed.xml', getFeedContent(site))

// Add to the sitemap page to pages
site.pages.push(feed);
});
site.pages.push(feed)
})

function getFeedContent(site: Site): string {
// Get the pages
const search = site.globalData.search as Search;
const search = site.globalData.search as Search
const feedPages = search.pages(
options.query,
options.sort,
options.limit,
) as Page[];
) as Page[]

// Sort the pages
feedPages.sort(buildSort(options.sort));
feedPages.sort(buildSort(options.sort))

const metas = isActiveProcessor(site, "metas")
const metas = isActiveProcessor(site, 'metas')
? feedPages[0].data.metas as FeedMetaData
: feedPages[0].data.site as FeedMetaData;
: feedPages[0].data.site as FeedMetaData

// deno-fmt-ignore
const atomfeed = `<?xml version="1.0" encoding="utf-8"?>
Expand All @@ -97,19 +97,19 @@ export default function (userOptions?: Partial<Options>) {
`}).join("").trim()}
</feed>`.trim();

return XMLFormat.default(atomfeed, options.options) as string;
return XMLFormat.default(atomfeed, options.options) as string
}

function isActiveProcessor(site: Site, processor: string): boolean {
const { processors } = site.processors;
const { processors } = site.processors

// deno-lint-ignore no-unused-vars
for (const [value, key] of processors) {
if (typeof value === "function" && value.name === processor) {
return true;
if (typeof value === 'function' && value.name === processor) {
return true
}
}
return false;
return false
}
};
}
}
4 changes: 2 additions & 2 deletions plugins/md5-cache-buster/deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Md5 } from "https://deno.land/[email protected]/hash/md5.ts";
export type { Message } from "https://deno.land/[email protected]/hash/md5.ts";
export { Md5 } from 'https://deno.land/[email protected]/hash/md5.ts'
export type { Message } from 'https://deno.land/[email protected]/hash/md5.ts'
Loading

0 comments on commit 1d2b69b

Please sign in to comment.