Skip to content

Commit 68abb9b

Browse files
authored
Merge pull request #395 from ReadAlongs/dev.ej/streamline-bundle
Streamline the bundles in the Offline HTML file: don't b64 encode what doesn't need to be, and clean up the formatting of the whole HTML file.
2 parents 206db87 + 61a42cf commit 68abb9b

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

packages/studio-web/src/app/b64.service.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ export class B64Service {
2323
private fileService: FileService,
2424
) {
2525
this.getBundle$().subscribe((bundle) => {
26-
this.jsAndFontsBundle$.next(bundle);
26+
this.jsAndFontsBundle$.next([
27+
this.indent(bundle[0], 6), //apply the indentation to the js bundle
28+
this.indent(bundle[1], 6),
29+
]);
2730
});
2831
}
2932
getBundle$(): Observable<[string, string]> {
3033
return forkJoin([
3134
this.http
3235
.get(this.JS_BUNDLE_URL, { responseType: "blob" })
33-
.pipe(
34-
switchMap((blob: Blob) => this.fileService.readFileAsData$(blob)),
35-
),
36+
.pipe(switchMap((blob: Blob) => this.fileService.readFile$(blob))),
37+
3638
this.http
3739
.get(this.FONTS_BUNDLE_URL, { responseType: "blob" })
3840
.pipe(switchMap((blob: Blob) => this.fileService.readFile$(blob))),
@@ -69,4 +71,13 @@ export class B64Service {
6971
reader.readAsDataURL(blob);
7072
});
7173
}
74+
75+
indent(str: string, level: number) {
76+
const indent = " ".repeat(level);
77+
78+
return str
79+
.split("\n")
80+
.map((line) => (line.trim() ? indent + line : line))
81+
.join("\n");
82+
}
7283
}

packages/studio-web/src/app/shared/download/download.service.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,22 @@ Please host all assets on your server, include the font and package imports defi
219219
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0">
220220
<meta name="generator" content="@readalongs/studio-web ${environment.packageJson.singleFileBundleVersion}">
221221
<title>${slots.title}</title>
222-
<style>${this.b64Service.jsAndFontsBundle$.value[1]}</style>
223-
<script src="${this.b64Service.jsAndFontsBundle$.value[0]}" version="${environment.packageJson.singleFileBundleVersion}" timestamp="${environment.packageJson.singleFileBundleTimestamp}"></script>
222+
<style>
223+
${this.b64Service.jsAndFontsBundle$.value[1]}
224+
</style>
225+
<script name="@readalongs/web-component" version="${environment.packageJson.singleFileBundleVersion}" timestamp="${environment.packageJson.singleFileBundleTimestamp}">
226+
${this.b64Service.jsAndFontsBundle$.value[0]}
227+
</script>
224228
</head>
225229
<body>
226-
<read-along version="${environment.packageJson.singleFileBundleVersion}" href="data:application/readalong+xml;base64,${rasB64}" audio="${b64Audio}" image-assets-folder="">
227-
<span slot="read-along-header">${slots.title}</span>
228-
<span slot="read-along-subheader">${slots.subtitle}</span>
230+
<read-along
231+
version="${environment.packageJson.singleFileBundleVersion}"
232+
href="data:application/readalong+xml;base64,${rasB64}"
233+
audio="${b64Audio}"
234+
image-assets-folder=""
235+
>
236+
<span slot="read-along-header">${slots.title}</span>
237+
<span slot="read-along-subheader">${slots.subtitle}</span>
229238
</read-along>
230239
</body>
231240
</html>
@@ -351,8 +360,14 @@ Please host all assets on your server, include the font and package imports defi
351360
</head>
352361
353362
<body>
354-
<!-- Here is how you declare the Web Component. Supported languages: en, fr -->
355-
<read-along href="assets/${basename}.readalong" audio="assets/${basename}.${audioExtension}" theme="light" language="en" image-assets-folder="assets/">
363+
<!-- Here is how you declare the Web Component. Supported languages: eng, fra, spa -->
364+
<read-along
365+
href="assets/${basename}.readalong"
366+
audio="assets/${basename}.${audioExtension}"
367+
theme="light"
368+
language="eng"
369+
image-assets-folder="assets/"
370+
>
356371
<span slot='read-along-header'>${slots.title}</span>
357372
<span slot='read-along-subheader'>${slots.subtitle}</span>
358373
</read-along>

0 commit comments

Comments
 (0)