Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active March 27, 2021 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/03cb0dc1bb344c8a0fb8e7e48de4aaaf to your computer and use it in GitHub Desktop.
Save mizchi/03cb0dc1bb344c8a0fb8e7e48de4aaaf to your computer and use it in GitHub Desktop.
<div>hello</div>
import * as path from "https://deno.land/std@0.91.0/path/mod.ts";
async function getTextFile(filepath: string) {
if (import.meta.url.startsWith("file://")) {
return await Deno.readTextFile(filepath);
} else {
const dir = path.dirname(import.meta.url);
const dest = path.join(dir, filepath);
const result = await fetch(dest).then((res) => res.text());
return result;
}
}
console.log(await getTextFile("./template.html"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment