Skip to content

Commit

Permalink
Cleanup old files
Browse files Browse the repository at this point in the history
Generate OpenGraph images with Satori
Add OpenGraph tags
Move to Picture instead of Image from astro:assets
Remove the '...' in truncated MDX
Add an x-cloak to avoid flicker on the mobile language selector
  • Loading branch information
Timothée Rebours committed Feb 29, 2024
1 parent f8e8698 commit 92d2625
Show file tree
Hide file tree
Showing 34 changed files with 1,826 additions and 379 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ pnpm-debug.log*

# Specific to the project
public_to_encrypt/*
public/og/
45 changes: 31 additions & 14 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@ import sitemap from '@astrojs/sitemap'
import AutoImport from 'astro-auto-import'
import icon from 'astro-icon'
import asides, { asideAutoImport } from './integrations/asides'

import moveOgImages from './integrations/moveOGImages.ts'
import arraybuffer from 'vite-plugin-arraybuffer'
import alpinejs from '@astrojs/alpinejs'

import react from '@astrojs/react'
import { env } from 'node:process'
// https://astro.build/config
export default defineConfig({
integrations: [AutoImport({
imports: [asideAutoImport]
}), asides(), vue(), tailwind(), mdx(), sitemap({
i18n: {
defaultLocale: 'en',
locales: {
en: 'en-US',
fr: 'fr-FR'
integrations: [
AutoImport({ imports: [asideAutoImport] }),
asides(),
vue(),
tailwind(),
mdx(),
sitemap({
i18n: {
defaultLocale: 'en',
locales: {
en: 'en-US',
fr: 'fr-FR'
}
}
}
}), icon(), alpinejs()],
trailingSlash: 'always',
}),
icon(),
alpinejs(),
react(),
moveOgImages()
],
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
Expand All @@ -31,5 +41,12 @@ export default defineConfig({
redirectToDefaultLocale: false
}
},
site: 'https://tex0l.github.io'
site: 'https://tex0l.github.io',
vite: {
plugins: [arraybuffer()],
optimizeDeps: { exclude: ['@resvg/resvg-js'] }
}
})

if (typeof env.PWD !== 'string') throw new Error('PWD is undefined')
export const PWD: string = env.PWD
7 changes: 6 additions & 1 deletion encryptAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ const encryptDir = async (dir, key) => {
else {
const relativePath = path.relative(toEncryptDir, dir)
await mkdir(path.join(publicEncrypted, relativePath), { recursive: true })
await writeFile(path.join(publicEncrypted, relativePath, file + '.encrypted'), await encryptFile(await readFile(path.join(toEncryptDir, relativePath, file)), key))
const encryptedFileName = path.join(publicEncrypted, relativePath, file + '.encrypted')
try {
await access(encryptedFileName, constants.F_OK)
} catch {
await writeFile(encryptedFileName, await encryptFile(await readFile(path.join(toEncryptDir, relativePath, file)), key))
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions integrations/moveOGImages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { AstroIntegration } from 'astro'
import { fileURLToPath } from 'node:url'
import { opendir, copyFile, mkdir } from 'node:fs/promises'
import { existsSync } from 'node:fs'
import AstroConfig, { PWD } from '../astro.config.ts'
import path from 'node:path'

export default function (): AstroIntegration {
return {
name: 'MoveOGImages',
hooks: {
'astro:build:done': async ({ dir, logger: _logger }) => {
const logger = _logger.fork('MoveOGImages')
const inputDir = await opendir(path.resolve(PWD, AstroConfig.publicDir ?? 'public', 'og'))
const outputDirPath = path.resolve(fileURLToPath(dir), 'og')
if (!existsSync(outputDirPath)) {
logger.info('Creating directory /og')
await mkdir(outputDirPath)
}
for await (const entry of inputDir) {
if (entry.isFile()) {
logger.info(`Copying /og/${entry.name}`)
await copyFile(path.resolve(entry.path, entry.name), path.resolve(outputDirPath, entry.name))
}
}
}
}
}
}
Loading

0 comments on commit 92d2625

Please sign in to comment.