Static site hosting via tangled
1class SiteConfig {
2 constructor({
3 tangledUrl,
4 knotDomain,
5 ownerDid,
6 repoName,
7 branch,
8 baseDir,
9 notFoundFilepath,
10 }) {
11 if (tangledUrl) {
12 if ([ownerDid, repoName].some((v) => !!v)) {
13 throw new Error("Cannot use ownerDid and repoName with url");
14 }
15 }
16 this.tangledUrl = tangledUrl;
17 this.ownerDid = ownerDid;
18 this.repoName = repoName;
19 this.knotDomain = knotDomain;
20 this.branch = branch;
21 this.baseDir = baseDir;
22 this.notFoundFilepath = notFoundFilepath;
23 }
24}
25
26export class Config {
27 constructor({ site, sites, subdomainOffset, cache = false }) {
28 if (site && sites) {
29 throw new Error("Cannot use both site and sites in config");
30 }
31 this.site = site ? new SiteConfig(site) : null;
32 this.sites = sites ? sites.map((site) => new SiteConfig(site)) : null;
33 this.subdomainOffset = subdomainOffset;
34 this.cache = cache;
35 }
36
37 static async fromFile(filepath) {
38 const fs = await import("fs");
39 const config = JSON.parse(fs.readFileSync(filepath, "utf8"));
40 return new Config(config);
41 }
42}