Skip to content

Commit 68f893a

Browse files
committed
Bit of code cleaning
1 parent c32f5ce commit 68f893a

File tree

3 files changed

+3
-100
lines changed

3 files changed

+3
-100
lines changed

res/js/index.ts

-93
Original file line numberDiff line numberDiff line change
@@ -37,96 +37,3 @@ const currentLanguage = (localStorage && localStorage[window.lsPrefix + 'current
3737

3838
const currentCategory = (localStorage && localStorage[window.lsPrefix + 'currentCategory']) ?
3939
localStorage[window.lsPrefix + 'currentCategory'] : 'all';
40-
41-
const ractive = new Ractive({
42-
el: '#ractive-target',
43-
template: reactiveTemplate,
44-
computed: {
45-
languages() {
46-
return Object.entries(this.get('languageMappings'));
47-
},
48-
categories() {
49-
const lang = this.get('selectedLanguage');
50-
const sims = this.get(`simulationsByLanguage.${lang}`);
51-
const makeCategoryId = this.get('makeCategoryId');
52-
return sims.reduce((acc, sim) => acc.concat(sim.categories), [])
53-
.sort((a, b) => makeCategoryId(a) < makeCategoryId(b) ? -1 : 1)
54-
.filter((val, index, arr) => makeCategoryId(val) !== makeCategoryId(arr[index - 1] || []));
55-
},
56-
simulations() {
57-
const lang = this.get('selectedLanguage');
58-
const sims = this.get(`simulationsByLanguage.${lang}`);
59-
const category = this.get('selectedCategory') || 'all';
60-
61-
if (category === 'all') {
62-
return sims;
63-
} else {
64-
return sims.filter(sim => {
65-
return !!~sim.categories.map(c => c.slug).indexOf(category);
66-
});
67-
}
68-
}
69-
},
70-
data: {
71-
simulationsByLanguage: window.importedData.simsByLanguage,
72-
selectedLanguage: currentLanguage,
73-
selectedCategory: currentCategory,
74-
languageMappings: window.importedData.languageMappings,
75-
76-
makeCategoryId(category: Category) {
77-
return category.slug;
78-
},
79-
makeCategoryName(category: Category) {
80-
return category.title;
81-
},
82-
getSlug: (item) => {
83-
return JSON.stringify(item);
84-
}
85-
},
86-
oninit() {
87-
this.observe('selectedLanguage', function (selectedLanguage) {
88-
if (localStorage) localStorage[window.lsPrefix + 'currentLanguage'] = selectedLanguage;
89-
});
90-
this.observe('selectedCategory', function (selectedCategory) {
91-
if (localStorage) localStorage[window.lsPrefix + 'currentCategory'] = selectedCategory;
92-
});
93-
this.on('showConfirm', function (ev) {
94-
const simulation: Simulation = ev.context;
95-
96-
const categoryHTML = simulation.categories.map(cat => `<li>${cat.title}</li>`).join('');
97-
const topicsHTML = simulation.topics.map(t => `<li>${t}</li>`).join('');
98-
99-
swal.fire({
100-
title: `${simulation.title}`,
101-
html: `
102-
<div>
103-
<img src='../I/${simulation.id}.png' />
104-
</div>
105-
<div class='flex-cont'>
106-
<div>
107-
<span>Categories</span>
108-
<ul>${categoryHTML}</ul>
109-
</div>
110-
<div>
111-
<span>Topics</span>
112-
<ul class='topics'>${topicsHTML}</ul>
113-
</div>
114-
</div>
115-
<div class='description'>${simulation.description}</div>`,
116-
showCloseButton: true,
117-
showCancelButton: true,
118-
confirmButtonText: 'Load'
119-
}).then(({dismiss}) => {
120-
const reasonsToCancel = [
121-
swal.DismissReason.cancel,
122-
swal.DismissReason.close,
123-
swal.DismissReason.esc,
124-
];
125-
if (reasonsToCancel.includes(dismiss)) return;
126-
const a = document.createElement('a');
127-
a.href = `${simulation.id}_${simulation.language}.html`;
128-
document.body.appendChild(a).click();
129-
});
130-
});
131-
}
132-
});

steps/export.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ const getNamespaceByExt = (ext: string): string => namespaces[ext] || '-';
6262

6363
const getKiwixPrefix = (ext: string): string => `../${getNamespaceByExt(ext)}/`;
6464

65-
const getLanguage = (fileName) => fileName.split('_').pop().split('.')[0];
66-
67-
const addKiwixPrefixes = function addKiwixPrefixes(file, targetDir) {
65+
const addKiwixPrefixes = function addKiwixPrefixes(file) {
6866
const resources = file.match(/[0-9a-f]{32}\.(svg|jpg|jpeg|png|js)/g) || [];
6967
return resources
7068
.reduce((file, resName) => {
@@ -99,7 +97,7 @@ const extractResources = async (target, targetDir: string): Promise<void> => {
9997
html = html.replace(fileName, `${getKiwixPrefix(ext)}${fileName}`);
10098

10199
let file = await fs.promises.readFile(`${inDir}${fileName}`, 'utf8');
102-
file = addKiwixPrefixes(file, targetDir);
100+
file = addKiwixPrefixes(file);
103101
return await fs.promises.writeFile(`${targetDir}${path.basename(fileName)}`, file, 'utf8');
104102
}));
105103
await fs.promises.writeFile(`${targetDir}${path.basename(file)}`, html, 'utf8');

steps/transform.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import * as fs from 'fs';
22
import md5 from 'md5';
3-
import * as glob from 'glob';
43
import * as path from 'path';
54
import * as dotenv from 'dotenv';
6-
import op from 'object-path';
75
import * as cheerio from 'cheerio';
86
import imagemin from 'imagemin';
97

@@ -110,7 +108,7 @@ const removeStrings = (html): string => {
110108
};
111109

112110
const extractBase64 = async (fileName, html): Promise<string> => {
113-
const b64files = html.match(/( src=)?'data:([A-Za-z-+\/]+);base64,[^']*/g);
111+
const b64files = html.match(/( src=)?'data:([A-Za-z-+/]+);base64,[^']*/g);
114112

115113
await Promise.all((b64files || [])
116114
.map(async b64entry => {

0 commit comments

Comments
 (0)