diff options
Diffstat (limited to 'packages/integrations/markdoc/src')
-rw-r--r-- | packages/integrations/markdoc/src/index.ts | 17 | ||||
-rw-r--r-- | packages/integrations/markdoc/src/utils.ts | 17 |
2 files changed, 16 insertions, 18 deletions
diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts index 781ae392e..71edf3095 100644 --- a/packages/integrations/markdoc/src/index.ts +++ b/packages/integrations/markdoc/src/index.ts @@ -4,8 +4,8 @@ import Markdoc from '@markdoc/markdoc'; import type { AstroConfig, AstroIntegration, ContentEntryType, HookParameters } from 'astro'; import fs from 'node:fs'; import { fileURLToPath, pathToFileURL } from 'node:url'; +import crypto from 'node:crypto'; import { - createNameHash, hasContentFlag, isValidUrl, MarkdocError, @@ -292,3 +292,18 @@ function shouldOptimizeImage(src: string) { // Optimize anything that is NOT external or an absolute path to `public/` return !isValidUrl(src) && !src.startsWith('/'); } + +/** + * Create build hash for manual Rollup chunks. + * @see 'packages/astro/src/core/build/plugins/plugin-css.ts' + */ +function createNameHash(baseId: string, hashIds: string[]): string { + const baseName = baseId ? path.parse(baseId).name : 'index'; + const hash = crypto.createHash('sha256'); + for (const id of hashIds) { + hash.update(id, 'utf-8'); + } + const h = hash.digest('hex').slice(0, 8); + const proposedName = baseName + '.' + h; + return proposedName; +} diff --git a/packages/integrations/markdoc/src/utils.ts b/packages/integrations/markdoc/src/utils.ts index 1daf8f026..8dd4075db 100644 --- a/packages/integrations/markdoc/src/utils.ts +++ b/packages/integrations/markdoc/src/utils.ts @@ -1,6 +1,4 @@ import matter from 'gray-matter'; -import crypto from 'node:crypto'; -import path from 'node:path'; import type { ErrorPayload as ViteErrorPayload } from 'vite'; /** @@ -112,18 +110,3 @@ export function hasContentFlag(viteId: string, flag: string): boolean { const flags = new URLSearchParams(viteId.split('?')[1] ?? ''); return flags.has(flag); } - -/** - * Create build hash for manual Rollup chunks. - * @see 'packages/astro/src/core/build/plugins/plugin-css.ts' - */ -export function createNameHash(baseId: string, hashIds: string[]): string { - const baseName = baseId ? path.parse(baseId).name : 'index'; - const hash = crypto.createHash('sha256'); - for (const id of hashIds) { - hash.update(id, 'utf-8'); - } - const h = hash.digest('hex').slice(0, 8); - const proposedName = baseName + '.' + h; - return proposedName; -} |