Skip to main content
Module

x/lume/core/loaders/module.ts

πŸ”₯ Static site generator for Deno πŸ¦•
Very Popular
Latest
File
import { isUrl } from "../utils/path.ts";import { isPlainObject } from "../utils/object.ts";import { env } from "../utils/env.ts";
import type { RawData } from "../file.ts";
/** Load a JavaScript/TypeScript file. Use a random hash to prevent caching */export default async function module(path: string): Promise<RawData> { const url = isUrl(path) ? path : `file://${path}`; const specifier = env<boolean>("LUME_LIVE_RELOAD") ? `${url}#${Date.now()}` : url;
const mod = await import(specifier); return toData(mod);}
/** Transform the imported module to RawData */export function toData(mod: Record<string, unknown>): RawData { const data: RawData = {};
for (const [name, value] of Object.entries(mod)) { if (name === "default") { if (isPlainObject(value)) { Object.assign(data, value); } else { data.content = value; } continue; }
data[name] = value; }
return data;}