Skip to content

Commit

Permalink
fix(indexservlet): escape </script> in embedded-topic
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerengels committed Sep 13, 2023
1 parent ba2eb56 commit a825a7d
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 69 deletions.
35 changes: 0 additions & 35 deletions server/server.iml

This file was deleted.

2 changes: 1 addition & 1 deletion server/src/main/java/kmap/IndexServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ else if ("blog".equals(page)) {
builder.append("<meta name=\"article:author\" content=\"").append(author).append("\">");

if (embeddedTopic != null)
builder.append("<script id=\"embedded-topic\" type=\"json\">").append(embeddedTopic).append("</script>");
builder.append("<script id=\"embedded-topic\" type=\"json\"><!--//--><![CDATA[//><!--").append(embeddedTopic).append("//--><!]]></script>");

string = string.replace("<meta gen=\"\">", builder);
string = string.replace("<meta jsonld=\"\">", jsonld != null
Expand Down
7 changes: 7 additions & 0 deletions server/src/main/resources/couchdb/export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

curl -X GET -u $1 http://localhost:5984/$2-map/_all_docs\?include_docs\=true\&attachments\=true > map.json
curl -X GET -u $1 http://localhost:5984/$2-test/_all_docs\?include_docs\=true\&attachments\=true > test.json
curl -X GET -u $1 http://localhost:5984/$2-state/_all_docs\?include_docs\=true > state.json
curl -X GET -u $1 http://localhost:5984/$2-course/_all_docs\?include_docs\=true > course.json
curl -X GET -u $1 http://localhost:5984/$2-feedback/_all_docs\?include_docs\=true > feedback.json
21 changes: 21 additions & 0 deletions server/src/main/resources/couchdb/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ./import.sh username:password <instance>
curl -X DELETE -u $1 http://127.0.0.1:5984/$2-map
curl -X DELETE -u $1 http://127.0.0.1:5984/$2-test
curl -X DELETE -u $1 http://127.0.0.1:5984/$2-state
curl -X DELETE -u $1 http://127.0.0.1:5984/$2-course
curl -X DELETE -u $1 http://127.0.0.1:5984/$2-feedback

curl -X PUT -u $1 http://localhost:5984/$2-map
curl -X PUT -u $1 http://localhost:5984/$2-test
curl -X PUT -u $1 http://localhost:5984/$2-state
curl -X PUT -u $1 http://localhost:5984/$2-course
curl -X PUT -u $1 http://localhost:5984/$2-feedback

#curl -X PUT -u $1 http://localhost:5984/$2-map/_design/net -d @design-map.json
#curl -X PUT -u $1 http://localhost:5984/$2-test/_design/test -d @design-test.json

curl -d @map.json -H "Content-type: application/json" -X POST -u $1 http://127.0.0.1:5984/$2-map/_bulk_docs
curl -d @test.json -H "Content-type: application/json" -X POST -u $1 http://127.0.0.1:5984/$2-test/_bulk_docs
curl -d @state.json -H "Content-type: application/json" -X POST -u $1 http://127.0.0.1:5984/$2-state/_bulk_docs
curl -d @course.json -H "Content-type: application/json" -X POST -u $1 http://127.0.0.1:5984/$2-course/_bulk_docs
curl -d @feedback.json -H "Content-type: application/json" -X POST -u $1 http://127.0.0.1:5984/$2-feedback/_bulk_docs
7 changes: 7 additions & 0 deletions server/src/main/resources/couchdb/transform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

node ../transformdocs.js map.json
node ../transformdocs.js test.json
node ../transformdocs.js state.json
node ../transformdocs.js course.json
node ../transformdocs.js feedback.json
5 changes: 0 additions & 5 deletions server/src/main/resources/export.sh

This file was deleted.

15 changes: 0 additions & 15 deletions server/src/main/resources/import.sh

This file was deleted.

20 changes: 10 additions & 10 deletions server/src/main/resources/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function(doc) {
if ('_' === doc.topic) return;
index("chapter", doc.chapter, {'store': true});
index("topic", doc.topic, {'store': true, 'boost': 2});
if (doc.summary)
index("summary", doc.summary, {'store': true, 'boost': 2});
if (doc.description)
index("description", doc.description, {'store': true});
if (doc.thumb)
index("thumb", doc.thumb, {'store': true, 'index': false});
function convert(docel) {
if ('_' === docel.topic) return;
index("chapter", docel.chapter, {'store': true});
index("topic", docel.topic, {'store': true, 'boost': 2});
if (docel.summary)
index("summary", docel.summary, {'store': true, 'boost': 2});
if (docel.description)
index("description", docel.description, {'store': true});
if (docel.thumb)
index("thumb", docel.thumb, {'store': true, 'index': false});
}
7 changes: 4 additions & 3 deletions server/src/main/resources/transformdocs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var fs = require("fs");
console.log("\n *START transformation* \n");
var content = fs.readFileSync("test.json");
var name = process.argv[2];
console.log("\n *START transformation of " + name + " * \n");
var content = fs.readFileSync(name);
var json = JSON.parse(content);
var docs = json.rows;
var newDocs = new Array();
Expand All @@ -12,7 +13,7 @@ docs.forEach(function(doc) {
var newJson = new Object();
newJson.docs = newDocs;
var newContent = JSON.stringify(newJson)
fs.writeFile('test.json', newContent, 'utf8', function(err) {
fs.writeFile(name, newContent, 'utf8', function(err) {
if (err) throw err;
console.log('complete');
});
Expand Down
120 changes: 120 additions & 0 deletions server/src/other/jsxgraph/central limit theorem.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!doctype html>
<html lang="de">
<head>
<title>Zentraler Grenzwertsatz</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<link rel='stylesheet' type='text/css' href='https://cdn.jsdelivr.net/npm/jsxgraph@latest/distrib/jsxgraph.css'/>
<script src='https://cdn.jsdelivr.net/npm/jsxgraph@latest/distrib/jsxgraphcore.js' type='text/javascript'></script>

<style>
body {
margin: 0px;
padding: 0px;
overflow: hidden;
}
.container {
display: grid;
grid-template-columns: 1fr;
}
.jxgbox { border-radius: 0px; border: none}
.term {
background-color: white;
}
</style>
</head>
<body>

<div class="container">
<div id='sliders' class='jxgbox' style='width: 100%; aspect-ratio: 12'></div>
<div id='board' class='jxgbox' style='width: 100%; aspect-ratio: 3'></div>
</div>

<script>

var olds = 1;

var sliders = JXG.JSXGraph.initBoard('sliders', { boundingbox: [0, 2, 18, 0], intl: { enabled: true, locale: 'de-DE'}, showNavigation: false, showZoom: false, showCopyright: false, pan: { enabled: false }});
var ns = sliders.create('slider', [[1, 1.3], [13, 1.3], [1, 1, 7]], {snapWidth: 1, ticks: { minorTicks: 1, drawLabels: true, label: {fontSize: 13, strokeColor: '#D55E00'} }, name: 'n', digits: 0, label: {fontSize: 14, strokeColor: '#D55E00'}});

var board = JXG.JSXGraph.initBoard('board', { boundingbox: [-3, .2, 30, -.03], axis: true, showNavigation: false, showZoom: false, showCopyright: false, pan: { enabled: false }});
sliders.addChild(board);

var mu = 7;
var si = 4;

const normal = x => 1/Math.sqrt(2 * Math.PI * si**2) * Math.exp(-1/2 * ((x-mu)/si)**2);
var f = board.create('functiongraph', [normal], {strokeWidth: 3, layer: 10});

function sums() {
const n = ns.Value();
const l = n * 5;
const arr = [];
for (let i = 0; i <= l; i++) {
arr.push(i + n);
}
return arr;
}
function abs() {
const n = ns.Value();
const il = n * 6;
const arr = [];
for (let i = n; i <= il; i++) {
let s = 0;
const kl = Math.floor((i-n)/6);
for (let k = 0; k <= kl; k++) {
const v = (-1)**k*JXG.Math.binomial(n,k)*JXG.Math.binomial(i-1-6*k,n-1);
s += v;
}
arr.push(Math.round(s));
}
return arr;
}
function rels(as) {
const n = ns.Value();
return as.map(a => a/6**n);
}

var chart, chartl;

function genchart() {
const n = ns.Value();
const ss = sums();
const as = abs();
const rs = rels(as);
chart = board.create('chart', [ss, rs], {chartStyle: 'bar', width: 1, color: '#66bb6a'});
for (let i = 0; i < chart[0].length; i++) {
const element = chart[0][i];
element.rendNode.style = "stroke: green; opacity: .5";
element.setAttribute({stroke: 'green', opacity: .5});
}
chartl = board.create('chart', [ss, rs], {chartStyle: 'point,line', width: 1, color: '#66bb6a'});
chartl[1].setAttribute({strokeColor: 'black', strokeWidth: 3, fillColor: 'none'});
for (let i = 0; i < chartl[0].length; i++) {
const element = chartl[0][i];
element.setAttribute({strokeColor:'green', fillColor: 'green', size: 1});
}
mu = n * 3.5
si = Math.sqrt(n*35/12);
f.updateCurve();
}

genchart();

ns.on('drag', () => {
const s = ns.Value().toFixed(0);
if (s === olds)
return;

board.suspendUpdate();
board.removeObject(chart);
board.removeObject(chartl);
genchart();
board.unsuspendUpdate();

olds = s;
});
</script>

</body>
</html>
97 changes: 97 additions & 0 deletions server/src/other/jsxgraph/normal-approx.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!doctype html>
<html lang="de">
<head>
<title>Entstehung der Normalverteilung</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<link rel='stylesheet' type='text/css' href='https://cdn.jsdelivr.net/npm/jsxgraph@latest/distrib/jsxgraph.css'/>
<script src='https://cdn.jsdelivr.net/npm/jsxgraph@latest/distrib/jsxgraphcore.js' type='text/javascript'></script>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js" crossorigin="anonymous"></script>

<style>
body {
margin: 0px;
padding: 0px;
overflow: hidden;
}
.container {
display: grid;
grid-template-columns: 1fr;
}
.jxgbox { border-radius: 0px; border: none}
.term {
background-color: white;
}
</style>
</head>
<body>

<div class="container">
<div id='sliders' class='jxgbox' style='width: 100%; aspect-ratio: 12'></div>
<div id='board' class='jxgbox' style='width: 100%; aspect-ratio: 3'></div>
</div>

<script>
var olds = 1;

var sliders = JXG.JSXGraph.initBoard('sliders', { boundingbox: [0, 2, 13, 0], showNavigation: false, showZoom: false, showCopyright: false, pan: { enabled: false }});
var ns = sliders.create('slider', [[1.5, 1.3], [9.5, 1.3], [1, 1, 5]], {snapWidth: 1, ticks: { drawLabels: true, label: {fontSize: 13, strokeColor: '#D55E00'} }, name: 'S', digits: 0, label: {fontSize: 14, strokeColor: '#D55E00'}});

var board = JXG.JSXGraph.initBoard('board', { boundingbox: [-100, .004, 1600, -.001], axis: true, showNavigation: false, showZoom: false, showCopyright: false, pan: { enabled: false }});
sliders.addChild(board);

const μ = 1024;
const σ = 128;
const nn = () => 2**(ns.Value()+4);

const normal = x => 1/Math.sqrt(2 * Math.PI * σ**2) * Math.exp(-1/2 * ((x-μ)/σ)**2);
var f = board.create('functiongraph', [normal], {strokeWidth: 2});

function dataX() {
const arr = [];
const n = nn();
for (let i = 0; i <= 2 * μ; i++) {
arr.push(μ / n + i * (2 * μ / n));
}
return arr;
}
function dataY() {
const arr = [];
const n = nn();
for (let k = 1; k <= n; k++) {
arr.push(JXG.Math.Numerics.I([(k - 1)*(2*μ) / n, (k * 2*μ) / n], normal) / ((2*μ) / n));
}
return arr;
}

var chart = board.create('chart', [dataX(), dataY()], { chartStyle: 'bar', width: (2*μ) / nn(), color: '#66bb6a' });
for (i = 0; i < chart[0].length; i++) {
element = chart[0][i];
element.rendNode.style = "strokeWidth: 1px; stroke: green";
}

ns.on('drag', () => {
const s = ns.Value().toFixed(0);
if (s === olds)
return;
const n = nn();

board.suspendUpdate();
for (let i = 0; i <= chart[0].length; i++) {
board.removeObject(chart[0][i]);
}
chart = board.create('chart', [dataX(), dataY()], { chartStyle: 'bar', width: (2*μ) / n, color: '#66bb6a' });
for (i = 0; i < chart[0].length; i++) {
element = chart[0][i];
element.rendNode.style = "strokeWidth: 1px; stroke: green";
}
board.unsuspendUpdate();

olds = s;
});
</script>

</body>
</html>
Loading

0 comments on commit a825a7d

Please sign in to comment.