-
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.
adjust prettier. add env var for wacs url. update packages
- Loading branch information
Showing
73 changed files
with
23,701 additions
and
10,979 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 |
---|---|---|
|
@@ -45,5 +45,5 @@ module.exports = { | |
} | ||
} | ||
] | ||
} | ||
}; | ||
// https://github.com/ota-meshi/eslint-plugin-astro |
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 |
---|---|---|
@@ -1,39 +1,39 @@ | ||
import type { IcfEnv } from "@customTypes/types" | ||
import { getHeaders, aTagHandler, allParamsAreValid } from "functions/shared" | ||
import type { IcfEnv } from "@customTypes/types"; | ||
import { getHeaders, aTagHandler, allParamsAreValid } from "functions/shared"; | ||
|
||
export const onRequestGet: PagesFunction = async (context) => { | ||
const request: Request = context.request | ||
const env = context.env as IcfEnv & typeof context.env | ||
const url = new URL(request.url) | ||
const user = url.searchParams?.get("user") as string | ||
const repo = url.searchParams?.get("repo") | ||
const bookKey = url.searchParams?.get("book") | ||
const chapter = url.searchParams?.get("chapter") | ||
const request: Request = context.request; | ||
const env = context.env as IcfEnv & typeof context.env; | ||
const url = new URL(request.url); | ||
const user = url.searchParams?.get("user") as string; | ||
const repo = url.searchParams?.get("repo"); | ||
const bookKey = url.searchParams?.get("book"); | ||
const chapter = url.searchParams?.get("chapter"); | ||
|
||
if (!allParamsAreValid([user, repo, bookKey, chapter])) { | ||
return new Response(null, { | ||
status: 400, | ||
statusText: "Missing parameters" | ||
}) | ||
}); | ||
} | ||
try { | ||
const baseUrl = env.PIPELINE_API_URL_BASE | ||
const finalUrl = `${baseUrl}/${user}/${repo}/${bookKey}/${chapter}.html` | ||
const response = await fetch(finalUrl) | ||
const baseUrl = env.PIPELINE_API_URL_BASE; | ||
const finalUrl = `${baseUrl}/${user}/${repo}/${bookKey}/${chapter}.html`; | ||
const response = await fetch(finalUrl); | ||
|
||
const newResp = new Response(response.body, { | ||
headers: getHeaders() | ||
}) | ||
}); | ||
// NOTE: TN AND BIBLE CHAP ARE BOTH CHAPTER/VERSE SCHEMAS, SO THE SAME API FETCHER FUNCTION IS HERE USED, BUT WE REWRITE ANY FOUND TN LINKS AS WELL HERE. | ||
const handler = new aTagHandler(user, "TN") | ||
const handler = new aTagHandler(user, "TN"); | ||
return new HTMLRewriter() | ||
.on("a[href*='tn-chunk-']", handler) | ||
.on("a[data-is-rc-link]", handler) | ||
.transform(newResp) | ||
.transform(newResp); | ||
} catch (error) { | ||
console.error(error) | ||
console.error(error); | ||
return new Response(null, { | ||
status: 404 | ||
}) | ||
}); | ||
} | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import type { IcfEnv } from "@customTypes/types" | ||
import { getHeaders, allParamsAreValid } from "functions/shared" | ||
import type { IcfEnv } from "@customTypes/types"; | ||
import { getHeaders, allParamsAreValid } from "functions/shared"; | ||
|
||
export const onRequestGet: PagesFunction = async (context) => { | ||
const request: Request = context.request | ||
const env = context.env as IcfEnv & typeof context.env | ||
const request: Request = context.request; | ||
const env = context.env as IcfEnv & typeof context.env; | ||
|
||
const url = new URL(request.url) | ||
const file = url.searchParams?.get("file") | ||
const user = url.searchParams?.get("user") | ||
const repo = url.searchParams?.get("repo") | ||
const url = new URL(request.url); | ||
const file = url.searchParams?.get("file"); | ||
const user = url.searchParams?.get("user"); | ||
const repo = url.searchParams?.get("repo"); | ||
|
||
if (!allParamsAreValid([file, user, repo])) { | ||
return new Response(null, { | ||
status: 400, | ||
statusText: "Invalid parameters" | ||
}) | ||
}); | ||
} | ||
|
||
try { | ||
// http://localhost/u/WA-Catalog/en_ulb/index.json; | ||
const baseUrl = env.PIPELINE_API_URL_BASE | ||
const finalUrl = `${baseUrl}/${user}/${repo}/${file}` | ||
const response = await fetch(finalUrl) | ||
const baseUrl = env.PIPELINE_API_URL_BASE; | ||
const finalUrl = `${baseUrl}/${user}/${repo}/${file}`; | ||
const response = await fetch(finalUrl); | ||
// E[foo*="bar"] | ||
const newResp = new Response(response.body, { | ||
headers: getHeaders() | ||
}) | ||
return newResp | ||
}); | ||
return newResp; | ||
} catch (error) { | ||
console.error(error) | ||
console.error(error); | ||
return new Response(null, { | ||
status: 404 | ||
}) | ||
}); | ||
} | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,51 +1,51 @@ | ||
import type { IcfEnv } from "@customTypes/types" | ||
import type { IcfEnv } from "@customTypes/types"; | ||
import { | ||
getRepoIndexLocal, | ||
getHeaders, | ||
allParamsAreValid, | ||
aTagHandler | ||
} from "functions/shared" | ||
} from "functions/shared"; | ||
|
||
export const onRequestGet: PagesFunction = async (context) => { | ||
const request: Request = context.request | ||
const env = context.env as IcfEnv & typeof context.env | ||
const url = new URL(request.url) | ||
const user = url.searchParams?.get("user") as string | ||
const repo = url.searchParams?.get("repo") as string | ||
const navSection = url.searchParams?.get("navSection") | ||
const request: Request = context.request; | ||
const env = context.env as IcfEnv & typeof context.env; | ||
const url = new URL(request.url); | ||
const user = url.searchParams?.get("user") as string; | ||
const repo = url.searchParams?.get("repo") as string; | ||
const navSection = url.searchParams?.get("navSection"); | ||
|
||
if (!allParamsAreValid([user, repo, navSection])) { | ||
return new Response(null, { | ||
status: 400, | ||
statusText: "Missing parameters" | ||
}) | ||
}); | ||
} | ||
// Used to rewrite A links via files Names | ||
const repoIndex = await getRepoIndexLocal(env, user, repo) | ||
const repoIndex = await getRepoIndexLocal(env, user, repo); | ||
const possibleFiles = | ||
repoIndex && repoIndex.navigation?.map((navOb) => navOb.File) | ||
repoIndex && repoIndex.navigation?.map((navOb) => navOb.File); | ||
|
||
try { | ||
// http://localhost/u/WA-Catalog/en_ulb/index.json; | ||
const baseUrl = env.PIPELINE_API_URL_BASE | ||
const finalUrl = `${baseUrl}/${user}/${repo}/${navSection}.html` | ||
const response = await fetch(finalUrl) | ||
const baseUrl = env.PIPELINE_API_URL_BASE; | ||
const finalUrl = `${baseUrl}/${user}/${repo}/${navSection}.html`; | ||
const response = await fetch(finalUrl); | ||
const newResp = new Response(response.body, { | ||
headers: getHeaders() | ||
}) | ||
const htmlRewriter = new HTMLRewriter() | ||
const handler = new aTagHandler(user, "TM") | ||
}); | ||
const htmlRewriter = new HTMLRewriter(); | ||
const handler = new aTagHandler(user, "TM"); | ||
// This line is to transform Hrefs inside the manual from absolute whatever.html into query parameters on the same origin such as | ||
// <a href="?section=intro#translate-terms">Terms to Know</a> | ||
possibleFiles && | ||
possibleFiles.forEach((possible) => { | ||
htmlRewriter.on(`a[href*='${possible}']`, handler) | ||
}) | ||
return htmlRewriter.transform(newResp) | ||
htmlRewriter.on(`a[href*='${possible}']`, handler); | ||
}); | ||
return htmlRewriter.transform(newResp); | ||
} catch (error) { | ||
console.error(error) | ||
console.error(error); | ||
return new Response(null, { | ||
status: 404 | ||
}) | ||
}); | ||
} | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import type { IcfEnv } from "@customTypes/types" | ||
import { getHeaders, aTagHandler, allParamsAreValid } from "functions/shared" | ||
import type { IcfEnv } from "@customTypes/types"; | ||
import { getHeaders, aTagHandler, allParamsAreValid } from "functions/shared"; | ||
|
||
export const onRequestGet: PagesFunction = async (context) => { | ||
const request: Request = context.request | ||
const env = context.env as IcfEnv & typeof context.env | ||
const request: Request = context.request; | ||
const env = context.env as IcfEnv & typeof context.env; | ||
|
||
const url = new URL(request.url) | ||
const user = url.searchParams?.get("user") as string //invariants are checked below | ||
const repo = url.searchParams?.get("repo") | ||
const navSection = url.searchParams?.get("navSection") | ||
const url = new URL(request.url); | ||
const user = url.searchParams?.get("user") as string; //invariants are checked below | ||
const repo = url.searchParams?.get("repo"); | ||
const navSection = url.searchParams?.get("navSection"); | ||
|
||
if (!allParamsAreValid([user, repo, navSection])) { | ||
return new Response(null, { | ||
status: 400, | ||
statusText: "Missing parameters" | ||
}) | ||
}); | ||
} | ||
|
||
class imgTagHandler { | ||
element(element: Element) { | ||
element.setAttribute("loading", "lazy") | ||
element.setAttribute("loading", "lazy"); | ||
} | ||
} | ||
|
||
try { | ||
// http://localhost/u/WA-Catalog/en_ulb/index.json; | ||
const baseUrl = env.PIPELINE_API_URL_BASE | ||
const finalUrl = `${baseUrl}/${user}/${repo}/${navSection}.html` | ||
const response = await fetch(finalUrl) | ||
const baseUrl = env.PIPELINE_API_URL_BASE; | ||
const finalUrl = `${baseUrl}/${user}/${repo}/${navSection}.html`; | ||
const response = await fetch(finalUrl); | ||
// E[foo*="bar"] | ||
const newResp = new Response(response.body, { | ||
headers: getHeaders() | ||
}) | ||
const aHandler = new aTagHandler(user, "TW") | ||
}); | ||
const aHandler = new aTagHandler(user, "TW"); | ||
return new HTMLRewriter() | ||
.on("a[data-is-rc-link]", aHandler) | ||
.on("a[href*='html']", aHandler) | ||
.on("img[src*='content.bibletranslationtools.org'", new imgTagHandler()) | ||
.transform(newResp) | ||
.transform(newResp); | ||
} catch (error) { | ||
console.error(error) | ||
console.error(error); | ||
return new Response(null, { | ||
status: 404 | ||
}) | ||
}); | ||
} | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,49 +1,47 @@ | ||
import { getHeaders, allParamsAreValid } from "functions/shared" | ||
import { bibleBookSortOrder } from "@lib/contants" | ||
import type { IcfEnv } from "@customTypes/types" | ||
import { getHeaders, allParamsAreValid } from "functions/shared"; | ||
import { bibleBookSortOrder } from "@lib/contants"; | ||
import type { IcfEnv } from "@customTypes/types"; | ||
|
||
export const onRequestPost: PagesFunction = async (context) => { | ||
const request: Request = context.request | ||
const request: Request = context.request; | ||
|
||
const env = context.env as IcfEnv & typeof context.env | ||
const url = new URL(request.url) | ||
const user = url.searchParams?.get("user") as string | ||
const repo = url.searchParams?.get("repo") | ||
const book = url.searchParams?.get("book") as string //type guard in if statement beneath; Cast here to satisfy typescript that I'm going to ensure that they are valid params | ||
const env = context.env as IcfEnv & typeof context.env; | ||
const url = new URL(request.url); | ||
const user = url.searchParams?.get("user") as string; | ||
const repo = url.searchParams?.get("repo"); | ||
const book = url.searchParams?.get("book") as string; //type guard in if statement beneath; Cast here to satisfy typescript that I'm going to ensure that they are valid params | ||
|
||
if (!allParamsAreValid([user, repo, book])) { | ||
return new Response(null, { | ||
status: 400, | ||
statusText: "Missing parameters" | ||
}) | ||
}); | ||
} | ||
|
||
try { | ||
// http://localhost/u/WA-Catalog/en_ulb/index.json; | ||
const baseUrl = env.PIPELINE_API_URL_BASE | ||
const finalUrl = `${baseUrl}/${user}/${repo}/source.usfm` | ||
const response = await fetch(finalUrl) | ||
const baseUrl = env.PIPELINE_API_URL_BASE; | ||
const finalUrl = `${baseUrl}/${user}/${repo}/source.usfm`; | ||
const response = await fetch(finalUrl); | ||
|
||
// @ NOTE! There is a convention in bible translation world (at least told to me) of NT matthew starting at 41 instead of 40: So, if the bibleBookSortOrder[book?.toUpperCase()] is > = 40, we need to plus 1 it. | ||
// @ NOTE! There is a convention in bible translation world (at least told to me) of NT matthew starting at 41 instead of 40: So, if the bibleBookSortOrder[book?.toUpperCase()] is > = 40, we need to plus 1 it. | ||
let sortOrder = bibleBookSortOrder[book?.toUpperCase()]; | ||
if (sortOrder >= 40) { | ||
sortOrder = sortOrder += 1; | ||
sortOrder = sortOrder += 1; | ||
} | ||
const fileName = `${ | ||
sortOrder | ||
}-${book?.toUpperCase()}` | ||
const fileName = `${sortOrder}-${book?.toUpperCase()}`; | ||
const newResp = new Response(response.body, { | ||
headers: { | ||
...getHeaders(), | ||
"Content-Type": "application/octet-stream", | ||
"content-disposition": `attachment; filename=${fileName}.usfm` | ||
} | ||
}) | ||
return newResp | ||
}); | ||
return newResp; | ||
} catch (error) { | ||
console.error(error) | ||
console.error(error); | ||
return new Response(null, { | ||
status: 404 | ||
}) | ||
}); | ||
} | ||
} | ||
}; |
Oops, something went wrong.