Cleaning up the javascript a bit.

main
gamerdonkey 2022-08-19 05:27:05 +00:00
parent 809ae9c737
commit 2b68db2401
1 changed files with 7 additions and 21 deletions

View File

@ -1,19 +1,3 @@
function parseArticleJSON_old() {
fetch('tokens.json')
.then((article) => article.json())
.then((article_json) => {
let output = ''
article_json.forEach(function(token) {
output += `${token.token} `
})
document.getElementById('article').innerHTML = output
})
.catch((error) => {
console.log(`Error fetching article: ${error}`)
document.getELementById('article').innerHTML = 'Error'
})
}
function createInputs(article) {
inputs = ''
article.tokens.forEach(function(token) {
@ -30,16 +14,17 @@ function createInputs(article) {
}
function showArticle(article) {
document.getElementById('title').innerHTML = article.title
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
let output = ''
let spaceBefore = false
const noSpaceBeforeTags = new Set(['.', ',', ')', ';', ':', '!', '?', "''", 'POS'])
const noSpaceBeforeTokens = new Set(["n't", ']'])
const noSpaceAfterTags = new Set(['(', '``'])
const noSpaceAfterTokens = new Set(['['])
article.tokens.forEach(function(token) {
document.getElementById('title').innerHTML = article.title
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
let output = ''
let spaceBefore = false
article.tokens.forEach(function(token) {
if(spaceBefore && !noSpaceBeforeTags.has(token.tag) && !noSpaceBeforeTokens.has(token.token)) {
output += ' '
}
@ -57,6 +42,7 @@ function showArticle(article) {
spaceBefore = false
}
})
document.getElementById('summary').innerHTML = output
document.getElementById('article').classList.add('visible')