Skip to content

Commit

Permalink
remove tagcloud which is no longer neeed
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksptang committed Jun 24, 2024
1 parent f8208c2 commit 21065e0
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 10 deletions.
103 changes: 103 additions & 0 deletions step-tools/src/main/resources/cloudflare_caching/createhomepagecache
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})

const url = "https://www.stepbible.org/?"
async function gatherResponse(response) {
const { headers } = response
const contentType = headers.get("content-type") || ""
if (contentType.includes("application/json")) {
console.log("json")
return JSON.stringify(await response.json())
}
else if (contentType.includes("application/text")) {
console.log("application")
return response.text()
}
else if (contentType.includes("text/html")) {
return response.text()
}
else {
console.log("other")
return response.text()
}
}

async function handleRequest(request) {
const userurl = request.url

// Function to parse query strings
function getParameterByName(name) {
name = name.replace(/[\[\]]/g, '\\$&')
name = name.replace(/\//g, '')
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(userurl)

if (!results) return null
else if (!results[2]) return ''
else if (results[2]) {
results[2] = results[2].replace(/\//g, '')
}

return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

const langs = ["en", "es", "zh", "zh-tw", "aa", "af", "ar", "az", "be", "bg", "bn", "cs", "cy", "de", "el", "et", "fa", "fi", "fr", "ga", "gl", "gu", "hi", "hr", "hu", "id", "in", "is", "it", "iw", "ja", "ka", "ko", "lt", "lv", "mk", "ml", "ms", "mt", "nl", "no", "pl", "pt", "ro", "ru", "ry", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tr", "uk", "ur", "uz", "vi"];
const respInit = {
headers: {
"content-type": "text/html;charset=UTF-8",
"accept-language": "en"
},
}
const languageSelected = getParameterByName('lang')
if ((typeof languageSelected === "string") && (langs.indexOf(languageSelected) > -1)) {
var init = {}
init = {
headers: {
"content-type": "text/html;charset=UTF-8",
"accept-language": languageSelected
},
}
const response = await fetch(url, init)
var results = await gatherResponse(response)
var resultsLines = results.split("\n")
var cfScriptRemoved = ""
var newResults = ""
var linesAdded = 0
for (var i = 0; i < resultsLines.length; i++ ) {
var curLine = resultsLines[i].trim()
if ((curLine.indexOf("<script>") == 0) &&
(curLine.indexOf("https://static.cloudflareinsights.com/beacon.min.js") > -1) &&
(curLine.endsWith("</script>"))) {
cfScriptRemoved = ", Cloudflare script was removed"
}
else if (curLine !== "") {
newResults += curLine + "\n"
linesAdded ++
}
}
await wwwcache.put(languageSelected, newResults)
return new Response("added " + linesAdded + " out of " + resultsLines.length + " lines for language " + languageSelected + " to Cloudflare KV " + cfScriptRemoved, respInit)
}
else {
var deleteName = getParameterByName('deleteKV')
if (typeof deleteName === "string") {
var deleteNames = []
if (deleteName === "all") {
deleteNames = langs
}
else
deleteNames = [ deleteName ]
for (var i = 0; i < deleteNames.length; i++) {
await wwwcache.delete(deleteNames[i])
}
return new Response("deleted " + deleteName + " from Cloudflare KV", respInit)
}
}
return new Response("don't understand your request", respInit)

}

addEventListener("fetch", event => {
return event.respondWith(handleRequest())
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export default {
async fetch(request, env) {
var ul = request.headers.get("Accept-Language");
if (typeof ul !== "string")
ul = "en"
const ulToCheck = ul.toLowerCase()
const ul2 = ulToCheck.substring(0,2)
var foundLang = "";
if ((ulToCheck.length >= 5) && (ul2 === "zh")) {
const ul5 = ulToCheck.substring(2,5)
if ((ul5 === "_tw") || (ul5 === "-tw") || (ul5 === "_hk") || (ul5 === "-hk"))
foundLang = 'zh-tw';
}
const langs = ["en", "es", "zh", "zh-tw", "aa", "af", "ar", "az", "be", "bg", "bn", "cs", "cy", "de", "el", "et", "fa", "fi", "fr", "ga", "gl", "gu", "hi", "hr", "hu", "id", "in", "is", "it", "iw", "ja", "ka", "ko", "lt", "lv", "mk", "ml", "ms", "mt", "nl", "no", "pl", "pt", "ro", "ru", "ry", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tr", "uk", "ur", "uz", "vi"];
var redirectCode = 301
if ((foundLang === "") && (langs.indexOf(ul2) > -1))
foundLang = ul2
if (foundLang !== "") {
var pageForUser = await env.wwwcache.get(foundLang, { cacheTtl: 4800 })
if ((typeof pageForUser === "string") && (pageForUser.length > 6000)) {
const respInit = {
headers: {
"content-type": "text/html;charset=UTF-8",
"cache-control": "no-cache",
},
}
return new Response(pageForUser, respInit)
}
else redirectCode = 302 // If redirect is needed, it is a temporary redirect because it is a language supported by STEP but does not have a KV for it.
}
return Response.redirect("https://www.stepbible.org/?q=reference=Gen.1", redirectCode);
},
};
2 changes: 1 addition & 1 deletion step-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<configuration>
<jsSourceDir>.</jsSourceDir>
<jsSourceFiles>
<jsSourceFile>libs/jquery.tagcloud.js</jsSourceFile>
<!-- <jsSourceFile>libs/jquery.tagcloud.js</jsSourceFile> -->
<jsSourceFile>js/backbone/models/model_sidebar.js</jsSourceFile>
<jsSourceFile>js/backbone/views/view_wordle_stat.js</jsSourceFile>
<jsSourceFile>js/backbone/views/view_history.js</jsSourceFile>
Expand Down
17 changes: 9 additions & 8 deletions step-web/src/main/webapp/js/backbone/views/view_wordle_stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,15 @@ var ViewLexiconWordle = Backbone.View.extend({
});

var links = $("a", container);
links.tagcloud({
size: {
start: statType == "SUBJECT" ? self.minSubjectFont : self.minFont,
end: self.maxFont,
unit: "px"
},
animate: isNextChapter
});
// June 21, 2024 - PT, probably no longer use
// links.tagcloud({
// size: {
// start: statType == "SUBJECT" ? self.minSubjectFont : self.minFont,
// end: self.maxFont,
// unit: "px"
// },
// animate: isNextChapter
// });

if (statType === 'WORD') {
links.hover(
Expand Down
2 changes: 1 addition & 1 deletion step-web/src/main/webapp/js/require_config_dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ requirejs.config({
shim : {
"menu_extras" : ["js/backbone/views/view_advanced_search"],
"sidebar" : ["js/backbone/models/model_sidebar", "js/backbone/views/view_wordle_stat",
"js/backbone/views/view_history", "libs/jquery.tagcloud"],
"js/backbone/views/view_history"], // "libs/jquery.tagcloud"],
"search" : ["_search_display_view", "_other_search"],
_other_search: ["_search_display_view", "js/backbone/views/view_display_text", "libs/dohighlight-min", "js/passage/step.alternatives"]
}
Expand Down

0 comments on commit 21065e0

Please sign in to comment.