-
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.
Site-specific parsers & streamline images
- Loading branch information
1 parent
2f8b114
commit 15a8824
Showing
6 changed files
with
93 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Parser } from "." | ||
|
||
const GithubParser: Parser = { | ||
matches: async (doc: Document, url: string) => { | ||
const regex = "^https://github.com/*" | ||
if (!url.match(regex)) return false | ||
const path = new URL(url).pathname.split("/") // ["", "user", "repo", ...] | ||
return path.length >= 3 | ||
}, | ||
parse: async (node: Node, url: string) => { | ||
console.log("Parsing Github") | ||
const path = new URL(url).pathname.split("/") // ["", "user", "repo", ...] | ||
const data = await fetch(`https://api.github.com/repos/${path[1]}/${path[2]}/readme`).then(res => res.json()) | ||
console.log(data) | ||
const decoded = atob(data.content) | ||
console.log(decoded) | ||
return { | ||
body: `URL: ${url}\nREADME: ${decoded}`, | ||
siteName: "Github", | ||
} | ||
} | ||
} | ||
|
||
export default GithubParser |
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,23 @@ | ||
import github from './github'; | ||
const parsers = [github]; | ||
|
||
export interface Parser { | ||
matches: (doc: Document, url: string) => Promise<boolean>, | ||
parse: (node: Node, url: string) => Promise<{ title?: string, description?: string, imageUrl?: string, body?: string, siteName?: string }> | ||
} | ||
|
||
const parseSiteSpecific = async (doc: Document, url: string) => { | ||
for (const parser of parsers) { | ||
try { | ||
if (await parser.matches(doc, url)) { | ||
const documentClone = doc.cloneNode(true); | ||
return await parser.parse(documentClone, url); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
return {}; | ||
} | ||
|
||
export default parseSiteSpecific; |
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 |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
.popup { | ||
max-height: 600px; | ||
width: 350px; | ||
overscroll-behavior: contain; | ||
} | ||
|
||
body { | ||
|