Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

refactor(core): move the domain helpers out of the extension

Luis Ortiz38db5b9a46fd
diff --git a/packages/core/src/guides/domain.ts b/packages/core/src/guides/domain.ts
new file mode 100644
index 0000000..b38e911
--- /dev/null
+++ b/packages/core/src/guides/domain.ts
@@ -0,0 +1,24 @@
+export function extractDomain(url: string): string {
+ try {
+ return new URL(url).hostname.replace(/^www\./, '');
+ } catch {
+ return '';
+ }
+}
+
+export function getMostCommonDomain(steps: { url?: string | null }[]): string {
+ const counts = new Map<string, number>();
+ for (const s of steps) {
+ const d = extractDomain(s.url || '');
+ if (d) counts.set(d, (counts.get(d) || 0) + 1);
+ }
+ let best = '';
+ let max = 0;
+ for (const [d, c] of counts) {
+ if (c > max) {
+ max = c;
+ best = d;
+ }
+ }
+ return best;
+}
diff --git a/packages/core/src/guides/service.ts b/packages/core/src/guides/service.ts
index db04ea5..4ccb2a9 100644
--- a/packages/core/src/guides/service.ts
+++ b/packages/core/src/guides/service.ts
@@ -2,6 +2,7 @@ import type { NarrationUpdate } from '@/core/capture/voice/narration-updates';
import { i18n } from '@/core/env';
import type { ScreenshotEdits } from '@/core/screenshot/types';
import { db } from './db';
+import { getMostCommonDomain } from './domain';
import { hashPayload } from './snapshot-hash';
import type { BlockType, CalloutVariant, DescriptionSource, Guide, Screenshot, Snapshot, Step } from './types';
@@ -278,7 +279,6 @@ export async function deleteStep(guideId: string, stepId: string): Promise<void>
}
export async function getGuideDomain(guideId: string): Promise<string> {
- const { getMostCommonDomain } = await import('@/lib/utils');
const steps = await db.steps.where('guideId').equals(guideId).sortBy('index');
return getMostCommonDomain(steps);
}
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index f46f978..9c4e0fc 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -1,3 +1,5 @@
+export { extractDomain, getMostCommonDomain } from '@/core/guides/domain';
+
import { type ClassValue, clsx } from 'clsx';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
@@ -58,31 +60,6 @@ export function formatRelativeTime(ts: number): string {
return locale ? dayjs(ts).locale(locale).fromNow() : dayjs(ts).fromNow();
}
-export function extractDomain(url: string): string {
- try {
- return new URL(url).hostname.replace(/^www\./, '');
- } catch {
- return '';
- }
-}
-
-export function getMostCommonDomain(steps: { url?: string | null }[]): string {
- const counts = new Map<string, number>();
- for (const s of steps) {
- const d = extractDomain(s.url || '');
- if (d) counts.set(d, (counts.get(d) || 0) + 1);
- }
- let best = '';
- let max = 0;
- for (const [d, c] of counts) {
- if (c > max) {
- max = c;
- best = d;
- }
- }
- return best;
-}
-
export function getFaviconUrl(url: string, size = 64): string {
try {
const full = /^https?:\/\//i.test(url) ? url : `https://${url}`;