Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/roe.dev. This is the code and content for my personal website, built in Nuxt. roe.dev
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import { addServerHandler, createResolver, defineNuxtModule, useNuxt } from 'nuxt/kit'import { resolveModulePath } from 'exsolve'import { defu } from 'defu'
const networks = { bluesky: 'bluesky', mastodon: 'mastodon', linkedin: 'linkedin',}
type Network = keyof typeof networks
type NetworkOptions = { bluesky?: { identifier: string password?: string } mastodon?: { identifier: string } linkedin?: { identifier: string }}
export default defineNuxtModule({ meta: { name: 'social-sync', configKey: 'social', }, defaults: { networks: {} as NetworkOptions, }, setup (options) { const nuxt = useNuxt() const resolver = createResolver(import.meta.url)
if (options.networks.bluesky) { options.networks.bluesky.password ||= '' }
nuxt.options.runtimeConfig.social = { networks: options.networks as any, }
// Prevent all the extra stuff `masto` will add nuxt.options.alias['node-fetch'] = 'node-fetch-native' nuxt.options.build.transpile.push( 'masto', '@mastojs/ponyfills', 'magic-string', )
const mockProxy = resolveModulePath('mocked-exports/proxy') nuxt.options.nitro = defu(nuxt.options.nitro, { alias: { 'eventemitter3': mockProxy, 'isomorphic-ws': mockProxy, }, })
nuxt.options.alias = defu(nuxt.options.alias, { '@jridgewell/sourcemap-codec': resolver.resolve('./mocks/sourcemap-codec'), 'qs': 'rollup-plugin-node-polyfills/polyfills/qs', 'change-case': 'scule', 'semver': resolver.resolve('./mocks/semver'), })
for (const network in options.networks) { if (!isSupportedNetwork(network)) { console.warn('Ignoring unsupported network:', network) continue } addServerHandler({ route: `/_social/${network}`, handler: resolver.resolve(`./runtime/server/_social/${network}.get.ts`), }) }
if (!nuxt.options.dev) { nuxt.options.nitro.routeRules ||= {} nuxt.options.nitro.routeRules['/_social/**'] = { isr: 60, swr: 60, } } },})
function isSupportedNetwork (id: string): id is Network { return id in networks}