-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some more docs and updated example codes
- Loading branch information
Showing
13 changed files
with
1,681 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { exec } from "child_process" | ||
import fs from "fs/promises" | ||
import { create } from "ipfs-http-client" | ||
import path from "path" | ||
import util from "util" | ||
|
||
const execPromise = util.promisify(exec) | ||
|
||
const ipfs = create({ url: `http://${await getHostIP()}:5001` }) | ||
const filePath = path.resolve("./dist/index.html") | ||
const ipnsKeyName = "purifyjs-compare" | ||
|
||
const hostIP = await getHostIP() | ||
if (!hostIP) { | ||
throw new Error("Could not retrieve host IP. Exiting.") | ||
} | ||
|
||
console.log("Pinning file...") | ||
const file = await fs.readFile(filePath) | ||
const { cid } = await ipfs.add(file) | ||
console.log("Pinned file CID:", cid.toString()) | ||
|
||
console.log("Updating IPNS record to:", cid) | ||
const result = await ipfs.name.publish(cid, { key: ipnsKeyName }) | ||
console.log("IPNS record updated to:", result.value) | ||
|
||
async function getHostIP() { | ||
try { | ||
const { stdout } = await execPromise("ip route | awk 'NR==1 {print $3}'") | ||
return stdout.trim() | ||
} catch (error) { | ||
console.error("Error getting host IP:", error) | ||
return null | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/compare/src/content/2-templating/2-styling/purify.js/CssScoped.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { tags } from "@purifyjs/core"; | ||
import { css, scope } from "./util-css"; | ||
|
||
const { div, h1, button } = tags; | ||
|
||
export function CssStyle() { | ||
return div() | ||
.use(scope(CssStyleCss)) | ||
.children( | ||
h1({ class: "title" }).textContent("I am red"), | ||
button({ | ||
style: "font-size: 10rem", | ||
}).textContent("I am a button"), | ||
); | ||
} | ||
|
||
const CssStyleCss = css` | ||
.title { | ||
color: red; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
apps/compare/src/content/2-templating/2-styling/purify.js/style.css
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
apps/compare/src/content/2-templating/2-styling/purify.js/util-css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Lifecycle } from "@purifyjs/core"; | ||
|
||
declare global { | ||
interface DOMStringMap { | ||
scope?: string; | ||
} | ||
} | ||
|
||
export const css = String.raw; | ||
|
||
export function sheet(css: string) { | ||
const sheet = new CSSStyleSheet(); | ||
sheet.replaceSync(css); | ||
return sheet; | ||
} | ||
|
||
export function scope(css: string): Lifecycle.OnConnected { | ||
return (element) => { | ||
if (element.dataset.scope) return; | ||
|
||
const scopeId = Math.random().toString(36).slice(2); | ||
document.adoptedStyleSheets.push( | ||
sheet( | ||
`@scope ([data-scope="${scopeId}"]) to ([data-scope]:not([data-scope="${scopeId}"]) > *) {${css}}`, | ||
), | ||
); | ||
element.dataset.scope = scopeId; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.