diff --git a/res/js/index.ts b/res/js/index.ts index 89892f5..b0c4269 100644 --- a/res/js/index.ts +++ b/res/js/index.ts @@ -1,6 +1,7 @@ import swal from 'sweetalert2'; import * as ArrayFrom from 'array-from'; import {Category, Simulation} from '../../lib/types'; +import { template as reactiveTemplate } from '../templates/reactive-template'; if (!(Array as any).from) (Array as any).from = ArrayFrom; @@ -39,7 +40,7 @@ const currentCategory = (localStorage && localStorage[window.lsPrefix + 'current const ractive = new Ractive({ el: '#ractive-target', - template: '#ractive-template', + template: reactiveTemplate, computed: { languages() { return Object.entries(this.get('languageMappings')); diff --git a/res/template.html b/res/template.html index d6f1817..e4adadb 100644 --- a/res/template.html +++ b/res/template.html @@ -38,50 +38,9 @@
- - - - + diff --git a/res/templates/catalog.ts b/res/templates/catalog.ts new file mode 100644 index 0000000..338f405 --- /dev/null +++ b/res/templates/catalog.ts @@ -0,0 +1,9 @@ + +export const catalogJs = (catalog: {}, lsPrefix: string): string => { + + return `window.importedData = ${JSON.stringify(catalog)}; + +window.lsPrefix = 'kiwix'; + +lsPrefix = '${lsPrefix}';`; +}; \ No newline at end of file diff --git a/res/templates/reactive-template.ts b/res/templates/reactive-template.ts new file mode 100644 index 0000000..fbe2618 --- /dev/null +++ b/res/templates/reactive-template.ts @@ -0,0 +1,32 @@ +export const template: string = ` +
+ {{#if languages.length > 1}} + + {{/if}} + +
+
+ {{#each simulations}} +
+ Screenshot of the {{display}} +
+ +

{{title}}

+
+
+ {{/each}} +
+`; \ No newline at end of file diff --git a/steps/export.ts b/steps/export.ts index 8736449..255fd64 100644 --- a/steps/export.ts +++ b/steps/export.ts @@ -19,6 +19,7 @@ import {Presets, SingleBar} from 'cli-progress'; // @ts-ignore import * as langs from '../state/get/languages.json'; import { exit } from 'yargs'; +import { catalogJs } from '../res/templates/catalog'; dotenv.config(); @@ -131,14 +132,12 @@ const exportTarget = async (target: Target) => { } // Generate index file - const templateHTML = await fs.promises.readFile(resDir + 'template.html', 'utf8'); - // Pretty hacky - doing a replace on the HTML. Investigate other ways - await fs.promises.writeFile(targetDir + 'index.html', - templateHTML - .replace('', JSON.stringify(catalog)) - .replace('', `lsPrefix = "${target.output}";`), 'utf8'); - - await Promise.all(glob.sync(`${resDir}/**/*`, {ignore: ['*.ts', 'template.html'], nodir: true}) + await fs.promises.copyFile(resDir + 'template.html', targetDir + 'index.html'); + + // Generate catalog JS + await fs.promises.writeFile(targetDir + 'catalog.js', catalogJs(catalog, target.output), 'utf8'); + + await Promise.all(glob.sync(`${resDir}/**/*`, {ignore: ['*/templates/*', '*.ts', 'template.html'], nodir: true}) .map(async (file) => fs.promises.copyFile(file, `${targetDir}${path.basename(file)}`)) ); diff --git a/test/e2e.test.ts b/test/e2e.test.ts index bdec785..85cdef7 100644 --- a/test/e2e.test.ts +++ b/test/e2e.test.ts @@ -93,7 +93,7 @@ describe('Validate ZIM', () => { const article = await zim.getArticleByUrl(`A/index.html`); expect(article).toBeDefined(); expect(article.mimeType).toEqual('text/html'); - expect(article.data.length).toBeGreaterThan(100000); + expect(article.data.length).toBeGreaterThan(1900); done(); });