Skip to content

Commit

Permalink
adjust prettier. add env var for wacs url. update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
wkelly17 committed Mar 14, 2024
1 parent 80f3e53 commit 47aad29
Show file tree
Hide file tree
Showing 73 changed files with 23,701 additions and 10,979 deletions.
1 change: 0 additions & 1 deletion .dev.vars
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
#PIPELINE_API_URL_BASE = http://127.0.0.1:10000/devstoreaccount1/web/u

PIPELINE_API_URL_BASE="https://read-dev.bibletranslationtools.org/u"
CHECK_VALID_REPO_URL="http://localhost:8080/api/CheckRepoExists?url=https://content.bibletranslationtools.org"
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ module.exports = {
}
}
]
}
};
// https://github.com/ota-meshi/eslint-plugin-astro
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ File/Folder tree below:
Notes, bible, questions, and commentary share a template:
Words and Manual have their own;

Example links:
Example links:

- Bible = http://localhost:3000/WycliffeAssociates/en_ulb
- TN = http://localhost:3000/WycliffeAssociates/en_tn
- TQ = http://localhost:3000/WycliffeAssociates/en_tq
Expand Down Expand Up @@ -59,7 +60,7 @@ Assets not processed by Vite. Fonts, and PWA icons etc;
### Tests

- e2e - uses [Playwright](https://playwright.dev/docs/intro).
- component testing - also playwright, but a few additional quirks worth readaing in docs. (currently experimental, but component testing isn't probably absolutely needed, [Playwright Components](https://playwright.dev/docs/test-components#how-to-get-started). Vitest can also test components, and has the upper hand on speed, but playwright already ships a browser, so components can be tested under different window conditions.
- component testing - also playwright, but a few additional quirks worth readaing in docs. (currently experimental, but component testing isn't probably absolutely needed, [Playwright Components](https://playwright.dev/docs/test-components#how-to-get-started). Vitest can also test components, and has the upper hand on speed, but playwright already ships a browser, so components can be tested under different window conditions.
- Unit Tests - Vitest: https://vitest.dev/guide/why.html; Can theoretically be used to test anything that isn't an astro file (e.g. components), but currently tests primarily cover logic in the lib folder.

### Additional Files
Expand Down
20 changes: 10 additions & 10 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { defineConfig } from "astro/config"
import { defineConfig } from "astro/config";

// https://astro.build/config
import tailwind from "@astrojs/tailwind"
import tailwind from "@astrojs/tailwind";

// https://astro.build/config
import cloudflare from "@astrojs/cloudflare"
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
import solidJs from "@astrojs/solid-js"
import solidJs from "@astrojs/solid-js";
// https://vite-pwa-org.netlify.app/frameworks/astro.html
import AstroPWA from "@vite-pwa/astro"
import { manifest } from "./manifest"
import { visualizer } from "rollup-plugin-visualizer"
import AstroPWA from "@vite-pwa/astro";
import { manifest } from "./manifest";
import { visualizer } from "rollup-plugin-visualizer";
const siteUrl = import.meta.env.PROD
? "https://read.bibleineverylanguage.org"
: import.meta.env.DEV
? "https://read-dev.bibleineverylanguage.org"
: ""
? "https://read-dev.bibleineverylanguage.org"
: "";
// https://astro.build/config
export default defineConfig({
site: siteUrl,
Expand Down Expand Up @@ -59,4 +59,4 @@ export default defineConfig({
})
]
}
})
});
38 changes: 19 additions & 19 deletions functions/api/getHtmlForChap.ts
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
})
});
}
}
};
34 changes: 17 additions & 17 deletions functions/api/getHtmlForCommentaryIndividualSection.ts
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
})
});
}
}
};
46 changes: 23 additions & 23 deletions functions/api/getHtmlForTm.ts
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
})
});
}
}
};
38 changes: 19 additions & 19 deletions functions/api/getHtmlForTw.ts
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
})
});
}
}
};
44 changes: 21 additions & 23 deletions functions/api/getUsfmSrcDownload.ts
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
})
});
}
}
};
Loading

0 comments on commit 47aad29

Please sign in to comment.