summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/src/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/markdoc/src/utils.ts')
-rw-r--r--packages/integrations/markdoc/src/utils.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/integrations/markdoc/src/utils.ts b/packages/integrations/markdoc/src/utils.ts
index ea5dda6db..ad964f56c 100644
--- a/packages/integrations/markdoc/src/utils.ts
+++ b/packages/integrations/markdoc/src/utils.ts
@@ -1,3 +1,5 @@
+import crypto from 'node:crypto';
+import path from 'node:path';
import matter from 'gray-matter';
import type { ErrorPayload as ViteErrorPayload } from 'vite';
@@ -96,3 +98,32 @@ export function isValidUrl(str: string): boolean {
return false;
}
}
+
+/**
+ * Identifies Astro components with propagated assets
+ * @see 'packages/astro/src/content/consts.ts'
+ */
+export const PROPAGATED_ASSET_FLAG = 'astroPropagatedAssets';
+
+/**
+ * @see 'packages/astro/src/content/utils.ts'
+ */
+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;
+}