1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-10-08 00:33:12 +02:00

migrate to biome (#944)

* migrate to biome

* cleanup

* fix

* use tsx

* script tweaks

* fix test runs

* path tweaks
This commit is contained in:
Matthias Kretschmann 2024-07-27 21:15:05 +01:00 committed by GitHub
parent d11617c2b2
commit 05ad0470c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
148 changed files with 3332 additions and 5953 deletions

View File

@ -1,29 +0,0 @@
{
"extends": [
"stylelint-config-standard",
"stylelint-config-css-modules",
"stylelint-prettier/recommended"
],
"plugins": ["stylelint-prettier"],
"syntax": "css",
"rules": {
"prettier/prettier": true,
"property-no-unknown": [
true,
{
"ignoreProperties": ["composes", "compose-with"]
}
],
"at-rule-no-unknown": [
true,
{
"ignoreAtRules": ["value", "include", "mixin", "extend"]
}
],
"selector-class-pattern": null,
"keyframes-name-pattern": null,
"custom-property-pattern": null,
"selector-id-pattern": null,
"media-feature-range-notation": "prefix"
}
}

View File

@ -1,12 +1,13 @@
import { defineConfig } from 'astro/config'
import { remarkLeadParagraph } from '../src/lib/remark-lead-paragraph/remark-lead-paragraph'
import { remarkToc } from '../src/lib/remark-toc/remark-toc'
import react from '@astrojs/react'
import sitemap from '@astrojs/sitemap'
import type { RemarkPlugins } from 'astro'
import expressiveCode from 'astro-expressive-code'
import redirectFrom from 'astro-redirect-from'
import config from './blog.config'
import { defineConfig } from 'astro/config'
import { getSlug } from '../src/lib/astro/getSlug'
import { remarkLeadParagraph } from '../src/lib/remark-lead-paragraph/remark-lead-paragraph'
import { remarkToc } from '../src/lib/remark-toc/remark-toc'
import config from './blog.config'
// https://astro.build/config
export default defineConfig({
@ -15,7 +16,7 @@ export default defineConfig({
cacheDir: '.astro',
trailingSlash: 'always',
markdown: {
remarkPlugins: [remarkLeadParagraph, remarkToc as any],
remarkPlugins: [remarkLeadParagraph, remarkToc] as unknown as RemarkPlugins,
shikiConfig: {
// https://github.com/shikijs/shiki/blob/main/docs/themes.md
theme: 'nord',

View File

@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged

View File

@ -1,14 +0,0 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"tabWidth": 2,
"endOfLine": "lf",
"plugins": ["prettier-plugin-astro"],
"overrides": [
{
"files": "*.astro",
"options": { "parser": "astro" }
}
]
}

View File

@ -140,7 +140,7 @@ If you want to know how, have a look at the respective components:
All SVG assets under `src/images/` and from select iconset dependencies are converted to Astro & React components before building the site. Compiled components are placed under `src/images/components/` and all include the cleaned SVGs as inline HTML.
All SVGs can then be imported from `@images/components` in all Astro or React components.
All SVGs can then be imported from `@/images/components` in all Astro or React components.
If you want to know how this works, have a look at the script:
@ -177,18 +177,12 @@ npm start
### 🔮 Linting
ESlint, Prettier, and Stylelint are setup for all linting purposes:
[Biome](https://biomejs.dev) is setup for all linting and formatting purposes:
```bash
npm run lint
```
To automatically format all code files:
```bash
npm run format
```
### 🔮 Type Checking
Type checking can be invoked to check all TypeScript code, including within .astro files:

26
biome.json Normal file
View File

@ -0,0 +1,26 @@
{
"extends": ["@kremalicious/config/biome"],
"overrides": [
{
"include": ["*.astro"],
"linter": {
"rules": {
"style": {
"useConst": "off",
"useImportType": "off"
}
}
}
},
{
"include": ["*.test.ts", "*.test.tsx"],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
}
}
}
}
]
}

View File

@ -1,4 +1,4 @@
import { z, type ImageFunction } from 'astro:content'
import { type ImageFunction, z } from 'astro:content'
const schemaShared = {
title: z.string(),

View File

@ -21,11 +21,7 @@ article kbd {
rgb(0 0 0 / 0%)
);
background-repeat: repeat-x;
box-shadow:
0 2px 0 #bbb,
0 3px 1px #999,
0 3px 0 #bbb,
inset 0 1px 1px #fff,
box-shadow: 0 2px 0 #bbb, 0 3px 1px #999, 0 3px 0 #bbb, inset 0 1px 1px #fff,
inset 0 -1px 3px #ccc;
}
@ -40,11 +36,8 @@ article kbd.dark {
rgb(0 0 0 / 0%)
);
background-repeat: no-repeat;
box-shadow:
0 2px 0 #000,
0 3px 1px #999,
inset 0 1px 1px #aaa,
inset 0 -1px 3px #272727;
box-shadow: 0 2px 0 #000, 0 3px 1px #999, inset 0 1px 1px #aaa, inset 0 -1px
3px #272727;
}
article kbd.ios {
@ -55,10 +48,8 @@ article kbd.ios {
background-color: #b7b7bc;
background-image: linear-gradient(to bottom, #efeff0, #b7b7bc);
background-repeat: repeat-x;
box-shadow:
0 1px 2px rgb(0 0 0 / 60%),
0 2px 3px rgb(0 0 0 / 10%),
inset 0 1px 0 #fff;
box-shadow: 0 1px 2px rgb(0 0 0 / 60%), 0 2px 3px rgb(0 0 0 / 10%), inset 0
1px 0 #fff;
}
article kbd.android {
@ -70,24 +61,15 @@ article kbd.android {
border-radius: 3px;
background-clip: padding-box;
background-color: #5e5e5e;
box-shadow:
0 2px 2px rgb(0 0 0 / 30%),
0 1px 0 #444,
inset 0 1px 0 #868686;
box-shadow: 0 2px 2px rgb(0 0 0 / 30%), 0 1px 0 #444, inset 0 1px 0 #868686;
}
article kbd.android.dark {
background: #222;
box-shadow:
0 2px 2px rgb(0 0 0 / 70%),
0 1px 0 #444,
inset 0 1px 0 #505050;
box-shadow: 0 2px 2px rgb(0 0 0 / 70%), 0 1px 0 #444, inset 0 1px 0 #505050;
}
article kbd.android.color {
background: #083c5b;
box-shadow:
0 2px 2px rgb(0 0 0 / 70%),
0 1px 0 #444,
inset 0 1px 0 #36647b;
box-shadow: 0 2px 2px rgb(0 0 0 / 70%), 0 1px 0 #444, inset 0 1px 0 #36647b;
}

View File

@ -1,39 +0,0 @@
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import prettierRecommended from 'eslint-plugin-prettier/recommended'
import eslintPluginAstro from 'eslint-plugin-astro'
import globals from 'globals'
import gitignore from 'eslint-config-flat-gitignore'
import testingLibrary from 'eslint-plugin-testing-library'
import { fixupPluginRules } from '@eslint/compat'
export default tseslint.config(
{
languageOptions: {
globals: { ...globals.browser }
}
},
gitignore(),
eslint.configs.recommended,
...tseslint.configs.recommended,
prettierRecommended,
...eslintPluginAstro.configs.recommended,
...eslintPluginAstro.configs['jsx-a11y-recommended'],
{
rules: {
'@typescript-eslint/no-explicit-any': 'warn'
// "astro/no-set-html-directive": "error"
}
},
// See https://github.com/testing-library/eslint-plugin-testing-library/issues/853
// current solution from https://github.com/testing-library/eslint-plugin-testing-library/issues/899#issuecomment-2121272355
{
files: ['**/?(*.)+(spec|test).[jt]sx'],
plugins: {
'testing-library': fixupPluginRules({
rules: testingLibrary.rules
})
},
rules: testingLibrary.configs.react.rules
}
)

8166
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,52 +17,36 @@
"test:unit": "vitest run --config './test/vitest.config.ts' --coverage",
"test:unit:watch": "vitest watch --config './test/vitest.config.ts' --coverage",
"test:e2e": "playwright test --config './test/playwright.config.ts'",
"lint": "run-p --silent lint:js lint:css lint:md",
"lint:js": "eslint './{src,test,scripts}/**/*.{ts,tsx,astro,mjs,js,cjs}'",
"lint:css": "stylelint --config '.config/.stylelintrc.json' 'src/**/*.css'",
"lint:md": "markdownlint --config '.config/.markdownlint.json' --ignore-path .gitignore --dot './**/*.{md,markdown}'",
"format": "prettier --ignore-path .gitignore --write '**/*.{js,jsx,ts,tsx,md,json,css,astro,yml}'",
"lint:md": "markdownlint --config '.config/markdownlint.json' --ignore-path .gitignore --dot './**/*.{md,markdown}'",
"lint:biome": "biome check --write .",
"lint": "run-p --silent lint:biome lint:md",
"deploy:s3": "./scripts/deploy-s3.sh",
"new": "node --loader ts-node/esm scripts/new/index.ts",
"create:icons": "node --loader ts-node/esm scripts/create-icons/index.ts",
"create:redirects": "node --loader ts-node/esm scripts/redirect-from.ts",
"new": "tsx scripts/new/index.ts",
"create:icons": "tsx scripts/create-icons/index.ts",
"create:redirects": "tsx scripts/redirect-from.ts",
"create:symlinks": "./scripts/create-symlinks.sh",
"move:downloads": "node --loader ts-node/esm scripts/move-downloads.ts",
"prepare": "husky .config/husky",
"lint:staged": "lint-staged"
"move:downloads": "tsx scripts/move-downloads.ts",
"prepare": "husky .config/husky"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,astro}": [
"prettier --write",
"eslint"
],
"*.css": [
"stylelint --config '.config/.stylelintrc.json' --fix",
"prettier --write"
],
"**/*.json": [
"prettier --write"
],
"*.md": [
"markdownlint --config '.config/.markdownlint.json'",
"prettier --write"
]
"*.{js,jsx,ts,tsx,astro,css,json,md}": ["biome check --write ."],
"*.md": ["markdownlint --config '.config/markdownlint.json'"]
},
"dependencies": {
"@astrojs/check": "^0.7.0",
"@astrojs/check": "^0.8.3",
"@astrojs/react": "^3.6.0",
"@astrojs/rss": "^4.0.6",
"@astrojs/rss": "^4.0.7",
"@astrojs/sitemap": "^3.1.6",
"@coingecko/cryptoformat": "^0.8.1",
"@nanostores/persistent": "^0.10.1",
"@nanostores/query": "^0.3.3",
"@nanostores/react": "^0.7.2",
"@radix-ui/react-select": "^2.1.1",
"@rainbow-me/rainbowkit": "^2.1.2",
"@rainbow-me/rainbowkit": "^2.1.3",
"@tanstack/react-query": "^5.45.1",
"astro": "4.11.0",
"astro": "4.12.2",
"astro-expressive-code": "^0.35.3",
"astro-redirect-from": "^1.0.8",
"astro-redirect-from": "^1.1.0",
"date-fns": "^3.6.0",
"dms2dec": "^1.1.0",
"fast-exif": "^2.0.1",
@ -77,32 +61,24 @@
"sharp": "^0.33.4",
"slugify": "^1.6.6",
"swr": "^2.2.5",
"viem": "^2.16.1",
"wagmi": "^2.10.4"
"viem": "^2.18.2",
"wagmi": "^2.12.1"
},
"devDependencies": {
"@eslint/compat": "^1.1.0",
"@eslint/js": "^9.5.0",
"@playwright/test": "^1.44.1",
"@testing-library/jest-dom": "^6.4.6",
"@biomejs/biome": "^1.8.3",
"@kremalicious/config": "^1.0.2",
"@playwright/test": "^1.45.3",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.0.0",
"@types/node": "^20.14.8",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitest/coverage-v8": "^1.6.0",
"eslint": "^8.57.0",
"eslint-config-flat-gitignore": "^0.1.5",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-astro": "^1.2.2",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.0",
"eslint-plugin-testing-library": "^6.2.2",
"globals": "^15.6.0",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"globby": "^14.0.2",
"hast-util-to-html": "^9.0.1",
"husky": "^9.0.11",
"identity-obj-proxy": "^3.0.0",
"jsdom": "^24.1.0",
"husky": "^9.1.3",
"jsdom": "^24.1.1",
"markdownlint-cli": "^0.41.0",
"mdast-util-to-hast": "^13.2.0",
"mdast-util-to-string": "^4.0.0",
@ -110,20 +86,13 @@
"node-iptc": "^1.0.5",
"npm-run-all": "^4.1.5",
"ora": "^8.0.1",
"prettier": "^3.3.2",
"prettier-plugin-astro": "^0.14.0",
"sharp-ico": "^0.1.5",
"stylelint": "^16.6.1",
"stylelint-config-css-modules": "^4.4.0",
"stylelint-config-standard": "^36.0.1",
"stylelint-prettier": "^5.0.0",
"svgo": "^3.2.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.2",
"typescript-eslint": "^7.13.1",
"svgo": "^3.3.2",
"tsx": "^4.16.2",
"typescript": "^5.5.4",
"unist-util-visit": "^5.0.0",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0"
"vitest": "^2.0.4"
},
"engines": {
"node": "20"
@ -133,10 +102,7 @@
"url": "https://github.com/kremalicious/blog.git"
},
"browserslist": {
"production": [
"defaults",
">0.2%"
],
"production": ["defaults", ">0.2%"],
"development": [
"last 1 chrome version",
"last 1 firefox version",

View File

@ -1,14 +1,14 @@
self.addEventListener('install', function () {
self.addEventListener('install', () => {
self.skipWaiting()
})
self.addEventListener('activate', function () {
self.addEventListener('activate', () => {
self.registration
.unregister()
.then(function () {
return self.clients.matchAll()
})
.then(function (clients) {
clients.forEach((client) => client.navigate(client.url))
.then(() => self.clients.matchAll())
.then((clients) => {
for (const client of clients) {
client.navigate(client.url)
}
})
})

View File

@ -1,6 +1,6 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import { test } from 'vitest'
import fs from 'fs/promises'
import path from 'path'
import { generateIcons } from './index'
const distDir = path.resolve(__dirname, 'tmp')

View File

@ -4,8 +4,8 @@
//
import fs from 'node:fs/promises'
import ps from 'node:path/posix'
import ora from 'ora'
import chalk from 'chalk'
import ora from 'ora'
import { toInnerSvg } from './svg.ts'
import { toAstroComponent } from './toAstroComponent.ts'
import { toReactComponent } from './toReactComponent.ts'
@ -25,24 +25,26 @@ const distDir = ps.resolve(currentDir, 'src/images/components')
// Data related to each icon exported by this package.
const icons = []
export async function generateIcons(distDir: string) {
export async function generateIcons(_distDir: string) {
const spinner = ora(
`${chalk.bold('[create-icons]')} Create icon components`
).start()
const dist = _distDir || distDir
// clean the distribution directory
await fs.rm(distDir, { force: true, recursive: true })
await fs.mkdir(distDir, { recursive: true })
await fs.mkdir(`${distDir}/react`, { recursive: true })
await fs.rm(dist, { force: true, recursive: true })
await fs.mkdir(dist, { recursive: true })
await fs.mkdir(`${dist}/react`, { recursive: true })
// copy the attribute typings file
await fs.copyFile(
ps.resolve(currentDir, 'scripts/create-icons/Props.d.ts'),
ps.resolve(distDir, 'Props.d.ts')
ps.resolve(dist, 'Props.d.ts')
)
await fs.copyFile(
ps.resolve(currentDir, 'scripts/create-icons/Props.d.ts'),
ps.resolve(`${distDir}/react`, 'Props.d.ts')
ps.resolve(`${dist}/react`, 'Props.d.ts')
)
// convert the SVG files into Astro & React components
@ -86,14 +88,14 @@ export async function generateIcons(distDir: string) {
// write the astro component to a file
await fs.writeFile(
ps.resolve(distDir, `${baseName}.astro`),
ps.resolve(dist, `${baseName}.astro`),
toAstroComponent(innerSVG, title),
'utf8'
)
// write the react component to a file
await fs.writeFile(
ps.resolve(`${distDir}/react`, `${baseName}.tsx`),
ps.resolve(`${dist}/react`, `${baseName}.tsx`),
toReactComponent(innerSVG, title),
'utf8'
)
@ -109,11 +111,11 @@ export async function generateIcons(distDir: string) {
}
// write the main Astro entry `index.ts` file
await fs.writeFile(ps.resolve(distDir, 'index.ts'), contentOfIndexJS, 'utf8')
await fs.writeFile(ps.resolve(dist, 'index.ts'), contentOfIndexJS, 'utf8')
// write the main React entry `react/index.ts` file
await fs.writeFile(
ps.resolve(`${distDir}/react`, 'index.ts'),
ps.resolve(`${dist}/react`, 'index.ts'),
contentOfIndexReactJS,
'utf8'
)
@ -121,7 +123,7 @@ export async function generateIcons(distDir: string) {
spinner.succeed(
`${chalk.bold('[create-icons]')} Generated ${
icons.length
} icons into @images/components.`
} icons into @/images/components.`
)
}

View File

@ -1,10 +1,11 @@
import { test, expect, vi } from 'vitest'
import fs from 'node:fs/promises'
import path from 'node:path'
import { glob } from 'glob'
import { copyZipFiles } from './move-downloads'
import { fileURLToPath } from 'node:url'
import chalk from 'chalk'
import { glob } from 'glob'
import type { Ora } from 'ora'
import { expect, test, vi } from 'vitest'
import { copyZipFiles } from './move-downloads'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
@ -21,12 +22,13 @@ test('copyZipFiles should copy zip files', async () => {
globMock.mockReturnValue(['file1.zip', 'file2.zip'])
const mockOra = {
text: '',
start: vi.fn(),
succeed: vi.fn(),
fail: vi.fn()
}
await copyZipFiles(sourceDir, destDir, mockOra as any)
await copyZipFiles(sourceDir, destDir, mockOra as unknown as Ora)
const file1 = await fs.readFile(path.join(destDir, 'file1.zip'), 'utf-8')
const file2 = await fs.readFile(path.join(destDir, 'file2.zip'), 'utf-8')

View File

@ -4,9 +4,9 @@
//
import fs from 'node:fs'
import path from 'node:path'
import globby from 'globby'
import ora, { type Ora } from 'ora'
import chalk from 'chalk'
import { globby } from 'globby'
import ora, { type Ora } from 'ora'
const sourceFolder = './content/articles/'
const destinationFolder = './public/get/'
@ -18,7 +18,7 @@ const spinner = ora(
function removeFolderContents(folderPath: string) {
if (fs.existsSync(folderPath)) {
fs.readdirSync(folderPath).forEach((file) => {
for (const file of fs.readdirSync(folderPath)) {
const filePath = path.join(folderPath, file)
if (fs.lstatSync(filePath).isDirectory()) {
removeFolderContents(filePath)
@ -26,7 +26,7 @@ function removeFolderContents(folderPath: string) {
} else {
fs.unlinkSync(filePath)
}
})
}
}
}
@ -46,22 +46,21 @@ export async function copyZipFiles(
// Find all files recursively in the source folder
const zipFiles = await globby(filesGlob, { cwd: source })
zipFiles.forEach((zipFile: string) => {
for (const zipFile of zipFiles) {
const sourcePath = path.join(source, zipFile)
const destinationPath = path.join(destination, path.basename(zipFile))
try {
// Copy the file to the destination folder
fs.copyFileSync(sourcePath, destinationPath)
} catch (error: any) {
} catch (error: unknown) {
spinner.fail(
`${chalk.bold('[move-downloads]')} Error copying ${zipFile}: ${
(error as Error).message
}`
)
return
}
})
}
spinner.succeed(
`${chalk.bold('[move-downloads]')} Copied ${

View File

@ -1,9 +1,9 @@
import fs from 'node:fs/promises'
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { slugify } from '../../src/lib/slugify/slugify.js'
import type { Ora } from 'ora'
import { slugify } from '../../src/lib/slugify/slugify.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const templatePath = path.join(__dirname, 'new-article.md')
@ -14,7 +14,7 @@ export async function createArticlePost(
title: string,
newDate?: string
) {
let file
let file = ''
const date = newDate
? new Date(newDate).toISOString()
: new Date().toISOString()
@ -44,7 +44,7 @@ export async function createArticlePost(
// create post file
await fs.appendFile(file, newContents)
spinner.succeed(`New post '${title}' created.`)
} catch (error: any) {
} catch (error: unknown) {
spinner.fail((error as Error).message)
}

View File

@ -1,9 +1,9 @@
import { existsSync, mkdirSync, readFileSync, promises as fs } from 'node:fs'
import { slugify } from '../../src/lib/slugify/slugify.js'
import { readOutExif } from '../../src/lib/exif/readOutExif.js'
import { promises as fs, existsSync, mkdirSync, readFileSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import type { Ora } from 'ora'
import { readOutExif } from '../../src/lib/exif/readOutExif.js'
import { slugify } from '../../src/lib/slugify/slugify.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const templatePathPhoto = path.join(__dirname, 'new-photo.md')
@ -14,10 +14,10 @@ export async function createPhotoPost(
photo: string,
photoTitle?: string
) {
let title
let titleSlug
let date
let postPhotoFile
let title: string | undefined
let titleSlug: string
let date: string
let postPhotoFile = ''
try {
const templatePhoto = readFileSync(templatePathPhoto).toString()
@ -25,7 +25,7 @@ export async function createPhotoPost(
if (!exifData) throw new Error('No exif data found in image')
const { iptc, exif } = exifData
title = iptc?.object_name || iptc?.title || photoTitle
title = iptc?.object_name || iptc?.caption || photoTitle
if (!title)
throw new Error(
'No title given. Add to IPTC, or use the format `npm run new photo path/to/photo.jpg "Title of post"'
@ -36,7 +36,7 @@ export async function createPhotoPost(
date = new Date(exif?.date).toISOString()
const dateShort = date.slice(0, 10)
const description = iptc?.caption
const keywords = (iptc?.keywords as string[])?.join(`\n - `)
const keywords = (iptc?.keywords as string[])?.join('\n - ')
const folderName = `${dateShort}-${titleSlug}`
const destination = `${dest}/${folderName}`
postPhotoFile = `${destination}/index.md`
@ -68,7 +68,7 @@ export async function createPhotoPost(
spinner.succeed(
`New photo post '${title}' under '${postPhotoFile}' created.`
)
} catch (error: any) {
} catch (error: unknown) {
spinner.fail((error as Error).message)
}

View File

@ -1,9 +1,9 @@
import { test, expect, describe, afterEach } from 'vitest'
import { createPhotoPost } from './createPhotoPost'
import { promises as fs } from 'node:fs'
import path from 'node:path'
import type { Ora } from 'ora'
import { afterEach, describe, expect, test } from 'vitest'
import { createArticlePost } from './createArticlePost'
import { createPhotoPost } from './createPhotoPost'
const destFolder = path.join('.', 'test/__fixtures__/tmp')
@ -67,7 +67,7 @@ describe('npm run new', () => {
.catch(() => false))
expect(fileExists).toBe(true)
expect(spinner.text).toContain(`New photo post`)
expect(spinner.text).toContain('New photo post')
// Compare the generated index.md with the fixture new-photo.md
const generatedContent =

View File

@ -1,7 +1,7 @@
import path from 'node:path'
import ora from 'ora'
import { createPhotoPost } from './createPhotoPost.js'
import { createArticlePost } from './createArticlePost.js'
import { createPhotoPost } from './createPhotoPost.js'
const postsPath = path.join('.', 'content', 'articles')
const photosPath = path.join('.', 'content', 'photos')

View File

@ -3,7 +3,7 @@ interface Window {
readonly [language: string]: {
readonly index: lunr.Index
readonly store: {
readonly [key: string]: any
readonly [key: string]: unknown
}
}
}

View File

@ -1,5 +1,5 @@
---
import { ChevronLeft } from '@images/components'
import { ChevronLeft } from '@/images/components'
---
<style>

View File

@ -1,6 +1,6 @@
---
import { markdownToHtml } from '@lib/markdown'
import { getRepo } from '@lib/github'
import { getRepo } from '@/lib/github'
import { markdownToHtml } from '@/lib/markdown'
import styles from './index.module.css'
type Props = {

View File

@ -1,5 +1,5 @@
---
import { Copy as CopyIcon } from '@images/components'
import { Copy as CopyIcon } from '@/images/components'
type Props = {
text: string

View File

@ -1,5 +1,5 @@
---
import Copy from '@components/Copy.astro'
import Copy from '@/components/Copy.astro'
type Props = {
address: string

View File

@ -1,8 +1,10 @@
---
import type React from 'react'
type Props = {
title: string
value: string
icon: any
icon: React.FunctionComponent
}
const { title, value, icon } = Astro.props

View File

@ -1,5 +1,5 @@
import { fireEvent, render, screen } from '@testing-library/react'
import { describe, it } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import ExifMap from './ExifMap'
describe('ExifMap', () => {

View File

@ -1,10 +1,12 @@
import { type ReactElement, useState, useEffect } from 'react'
import { Map, Marker } from 'pigeon-maps'
import type { Gps } from '@/lib/exif'
import { Marker, Map as PigeonMap } from 'pigeon-maps'
import { type ReactElement, useEffect, useState } from 'react'
const mapbox =
(mapboxId: string) => (x: string, y: string, z: string, dpr: number) =>
(mapboxId: string) =>
(x: number, y: number, z: number, dpr: number | undefined) =>
`https://api.mapbox.com/styles/v1/mapbox/${mapboxId}/tiles/256/${z}/${x}/${y}${
dpr >= 2 ? '@2x' : ''
dpr && dpr >= 2 ? '@2x' : ''
}?access_token=${import.meta.env.PUBLIC_MAPBOX_ACCESS_TOKEN}`
const providers = {
@ -14,11 +16,7 @@ const providers = {
type Theme = 'light' | 'dark'
export default function ExifMap({
gps
}: {
gps: { latitude: number; longitude: number }
}): ReactElement {
export default function ExifMap({ gps }: { gps: Gps }): ReactElement {
const theme = document?.documentElement?.getAttribute('data-theme') as Theme
const [zoom, setZoom] = useState(12)
@ -29,6 +27,7 @@ export default function ExifMap({
setProvider(() => providers[theme])
}
// biome-ignore lint/correctness/useExhaustiveDependencies: handleThemeChange not needed in deps
useEffect(() => {
if (!window) return
@ -41,17 +40,17 @@ export default function ExifMap({
const { latitude, longitude } = gps
return (
<Map
<PigeonMap
center={[latitude, longitude]}
zoom={zoom}
height={220}
dprs={[1, 2]}
attribution={false}
provider={provider as any}
provider={provider}
metaWheelZoom={true}
metaWheelZoomWarning={'META+wheel to zoom'}
>
<Marker anchor={[latitude, longitude]} payload={1} onClick={zoomIn} />
</Map>
</PigeonMap>
)
}

View File

@ -1,16 +1,16 @@
---
import type { Exif } from '@lib/exif'
import {
Aperture,
Camera,
Crosshair,
Aperture,
Maximize,
Stopwatch,
Sun,
Maximize
} from '@images/components'
Sun
} from '@/images/components'
import type { Exif } from '@/lib/exif'
import ExifData from './ExifData.astro'
import styles from './index.module.css'
import ExifMap from './ExifMap.tsx'
import styles from './index.module.css'
type Props = {
exif: Exif

View File

@ -47,8 +47,8 @@
}
.map {
composes: breakout from '@layouts/Base/index.module.css';
composes: frame from '@components/Picture/index.module.css';
composes: breakout from '@/layouts/Base/index.module.css';
composes: frame from '@/components/Picture/index.module.css';
height: 220px;
margin-top: calc(var(--spacer) * 2);
}

View File

@ -1,6 +1,6 @@
---
import { Github, Jsonfeed, Mastodon, Rss } from '@/images/components'
import styles from './Networks.module.css'
import { Rss, Mastodon, Github, Jsonfeed } from '@images/components'
type Props = {
links: string[]

View File

@ -1,9 +1,9 @@
---
import { Image } from 'astro:assets'
import Networks from './Networks.astro'
import Location from '../Location'
import avatar from '@images/avatar.jpg'
import avatar from '@/images/avatar.jpg'
import config from '@config/blog.config'
import Location from '../Location'
import Networks from './Networks.astro'
import styles from './Vcard.module.css'
const { author, rss, jsonfeed } = config

View File

@ -1,5 +1,5 @@
.avatar {
composes: frame from '@components/Picture/index.module.css';
composes: frame from '@/components/Picture/index.module.css';
border: 2px solid transparent;
border-radius: 50% !important;
margin-bottom: calc(var(--spacer) / 3);

View File

@ -1,8 +1,8 @@
---
import { Github, Bitcoin } from '@images/components'
import { Bitcoin, Github } from '@/images/components'
import config from '@config/blog.config'
import Vcard from './Vcard.astro'
import styles from './index.module.css'
import config from '@config/blog.config'
const year = new Date().getFullYear()
const { name, url, github } = config.author

View File

@ -1,8 +1,8 @@
---
import Menu from '@components/Menu/index.astro'
import Search from '@features/Search/index.astro'
import ThemeSwitch from '@components/ThemeSwitch/index.astro'
import { Logo } from '@images/components'
import Menu from '@/components/Menu/index.astro'
import ThemeSwitch from '@/components/ThemeSwitch/index.astro'
import Search from '@/features/Search/index.astro'
import { Logo } from '@/images/components'
import styles from './index.module.css'
---

View File

@ -27,7 +27,7 @@
.title {
display: block;
/* stylelint-disable-next-line font-family-no-missing-generic-family-keyword */
font: 0/0 a;
font: 0 / 0 a;
color: transparent;
text-shadow: none;
background-color: transparent;

View File

@ -1,4 +1,4 @@
import { type InputHTMLAttributes, type ReactElement } from 'react'
import type { InputHTMLAttributes, ReactElement } from 'react'
import styles from './index.module.css'
export default function Input({

View File

@ -1,8 +1,8 @@
---
import PostTitle from '@layouts/Post/Title.astro'
import styles from './index.module.css'
import type { CollectionEntry } from 'astro:content'
import LinkActions from '@layouts/Post/LinkActions.astro'
import LinkActions from '@/layouts/Post/LinkActions.astro'
import PostTitle from '@/layouts/Post/Title.astro'
import styles from './index.module.css'
type Props = {
post: CollectionEntry<'articles' | 'links'>

View File

@ -1,5 +1,5 @@
import { Icon as LoaderIcon } from '@/images/components/react/Loader'
import styles from './Loader.module.css'
import { Icon as LoaderIcon } from '@images/components/react/Loader'
export function Loader() {
// TODO: fix React props for generated SVG components for class/className

View File

@ -1,14 +1,14 @@
import {
describe,
it,
expect,
beforeAll,
afterAll,
vi,
type MockInstance
} from 'vitest'
import { render, screen } from '@testing-library/react'
import * as nanostores from '@nanostores/react'
import { render, screen } from '@testing-library/react'
import {
type MockInstance,
afterAll,
beforeAll,
describe,
expect,
it,
vi
} from 'vitest'
import Location from '.'
const mockData = {

View File

@ -1,5 +1,5 @@
import { $location } from '@/stores/location'
import { useStore } from '@nanostores/react'
import { $location } from '@stores/location'
import { formatDistanceToNowStrict } from 'date-fns'
import { LocationItem } from './LocationItem'
import styles from './index.module.css'

View File

@ -1,5 +1,5 @@
---
import Hamburger from '@components/Hamburger.astro'
import Hamburger from '@/components/Hamburger.astro'
import config from '@config/blog.config'
import styles from './index.module.css'

View File

@ -1,5 +1,5 @@
---
import { ChevronRight } from '@images/components'
import { ChevronRight } from '@/images/components'
type Props = {
href: string

View File

@ -1,6 +1,6 @@
---
import { ChevronLeft, ChevronRight } from '@/images/components'
import styles from './index.module.css'
import { ChevronLeft, ChevronRight } from '@images/components'
type Props = {
prevPagePath?: string

View File

@ -1,6 +1,6 @@
---
import type { CollectionEntry } from 'astro:content'
import Picture from '@components/Picture/index.astro'
import Picture from '@/components/Picture/index.astro'
type Props = { post: CollectionEntry<'photos'> }

View File

@ -1,7 +1,7 @@
---
import { getImage, type ImgAttributes } from 'astro:assets'
import styles from './index.module.css'
import { type ImgAttributes, getImage } from 'astro:assets'
import type { ImageMetadata, ImageOutputFormat } from 'astro'
import styles from './index.module.css'
type Props = ImgAttributes & {
src: ImageMetadata

View File

@ -1,8 +1,8 @@
---
import PostTitle from '@layouts/Post/Title.astro'
import styles from './index.module.css'
import Picture from '@components/Picture/index.astro'
import type { CollectionEntry } from 'astro:content'
import Picture from '@/components/Picture/index.astro'
import PostTitle from '@/layouts/Post/Title.astro'
import styles from './index.module.css'
type Props = {
post: CollectionEntry<'articles' | 'links'>

View File

@ -33,7 +33,7 @@
}
.empty {
composes: frame from '@components/Picture/index.module.css';
composes: frame from '@/components/Picture/index.module.css';
display: block;
min-height: 95px;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAACaADAAQAAAABAAAACQAAAAAvQpmhAAAAHElEQVQYGWNgoBL4T8gcggoIGcBA0ASCCmhsBQBhFwX7u70C8QAAAABJRU5ErkJggg==');

View File

@ -1,10 +1,10 @@
---
import type { CollectionEntry } from 'astro:content'
import PhotoTeaser from '@/components/PhotoTeaser.astro'
import PostTeaser from '@/components/PostTeaser/index.astro'
import { getAllPostsForSearch } from '@/lib/astro'
import Fuse from 'fuse.js'
import styles from './index.module.css'
import PhotoTeaser from '@components/PhotoTeaser.astro'
import PostTeaser from '@components/PostTeaser/index.astro'
import { getAllPostsForSearch } from '@lib/astro'
type Props = {
post: CollectionEntry<'articles' | 'photos' | 'links'>

View File

@ -3,7 +3,7 @@ type Props = {
name: string
url: string
count?: number
style?: any
style?: string | astroHTML.JSX.CSSProperties | null | undefined
}
const { name, url, count, style } = Astro.props

View File

@ -1,5 +1,5 @@
---
import { Sun, Moon } from '@images/components'
import { Moon, Sun } from '@/images/components'
import styles from './index.module.css'
---

View File

@ -1,8 +1,8 @@
import { test, expect, beforeAll } from 'vitest'
import { beforeAll, expect, test } from 'vitest'
function resetDocument() {
globalThis.localStorage = {
getItem: () => undefined,
getItem: () => null,
setItem: () => {}
} as any
@ -63,11 +63,14 @@ test('data-theme attribute is set based on system preference', async () => {
})
test('data-theme attribute changes on system preference change', async () => {
let changeCallback: any = () => {}
let changeCallback: ({ matches }: { matches: boolean }) => void = () => {}
globalThis.window.matchMedia = () =>
({
matches: false,
addEventListener: (_: any, callback: any) => {
addEventListener: (
_: any,
callback: ({ matches }: { matches: boolean }) => void
) => {
changeCallback = callback
}
}) as any

View File

@ -1,6 +1,6 @@
import { type ReactElement } from 'react'
import styles from './Empty.module.css'
import type { ReactElement } from 'react'
import type { Post } from '../Search'
import styles from './Empty.module.css'
const SearchResultsEmpty = ({
query,