client/app: Fixed relative links in app manifest

This commit is contained in:
Shyam Sunder 2018-09-04 21:55:59 -04:00 committed by rr-
parent 116919d2a2
commit 7081b5be90
3 changed files with 33 additions and 28 deletions

View File

@ -17,9 +17,8 @@ WORKDIR /var/www
RUN \ RUN \
# Create init file # Create init file
echo "#!/bin/sh" >> /init && \ echo "#!/bin/sh" >> /init && \
echo 'sed -i "s|__BACKEND__|${BACKEND_HOST}|" /etc/nginx/nginx.conf' \ echo 'sed -i "s|__BACKEND__|${BACKEND_HOST}|" /etc/nginx/nginx.conf' >> /init && \
>> /init && \ echo 'sed -i "s|__BASEURL__|${BASE_URL:-/}|g" /var/www/index.htm /var/www/manifest.json' >> /init && \
echo 'sed -i "s|__BASEURL__|${BASE_URL:-/}|" /var/www/index.htm' >> /init && \
echo 'exec nginx' >> /init && \ echo 'exec nginx' >> /init && \
chmod a+x /init chmod a+x /init

View File

@ -1,19 +0,0 @@
{
"name": "szurubooru",
"icons": [
{
"src": "/img/android-chrome-192x192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/img/android-chrome-512x512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "/",
"theme_color": "#24aadd",
"background_color": "#ffffff",
"display": "standalone"
}

View File

@ -28,6 +28,26 @@ const external_js = [
'nprogress', 'nprogress',
]; ];
const app_manifest = {
name: 'szurubooru',
icons: [
{
src: baseUrl() + 'img/android-chrome-192x192.png',
type: 'image/png',
sizes: '192x192'
},
{
src: baseUrl() + 'img/android-chrome-512x512.png',
type: 'image/png',
sizes: '512x512'
}
],
start_url: baseUrl(),
theme_color: '#24aadd',
background_color: '#ffffff',
display: 'standalone'
}
// ------------------------------------------------- // -------------------------------------------------
const fs = require('fs'); const fs = require('fs');
@ -45,14 +65,16 @@ function gzipFile(file) {
execSync('gzip -6 -k ' + file); execSync('gzip -6 -k ' + file);
} }
function baseUrl() {
return process.env.BASE_URL ? process.env.BASE_URL : '/';
}
// ------------------------------------------------- // -------------------------------------------------
function bundleHtml() { function bundleHtml() {
const underscore = require('underscore'); const underscore = require('underscore');
const babelify = require('babelify'); const babelify = require('babelify');
const baseUrl = process.env.BASE_URL ? process.env.BASE_URL : '/';
function minifyHtml(html) { function minifyHtml(html) {
return require('html-minifier').minify(html, { return require('html-minifier').minify(html, {
removeComments: true, removeComments: true,
@ -62,7 +84,7 @@ function bundleHtml() {
} }
const baseHtml = readTextFile('./html/index.htm') const baseHtml = readTextFile('./html/index.htm')
.replace('<!-- Base HTML Placeholder -->', `<base href="${baseUrl}"/>`); .replace('<!-- Base HTML Placeholder -->', `<base href="${baseUrl()}"/>`);
fs.writeFileSync('./public/index.htm', minifyHtml(baseHtml)); fs.writeFileSync('./public/index.htm', minifyHtml(baseHtml));
let compiledTemplateJs = [ let compiledTemplateJs = [
@ -198,12 +220,13 @@ function bundleConfig() {
}; };
fs.writeFileSync('./js/.config.autogen.json', JSON.stringify(config)); fs.writeFileSync('./js/.config.autogen.json', JSON.stringify(config));
console.info('Generated config file');
} }
function bundleBinaryAssets() { function bundleBinaryAssets() {
fs.copyFileSync('./img/favicon.png', './public/img/favicon.png'); fs.copyFileSync('./img/favicon.png', './public/img/favicon.png');
fs.copyFileSync('./img/transparency_grid.png', './public/img/transparency_grid.png'); fs.copyFileSync('./img/transparency_grid.png', './public/img/transparency_grid.png');
console.info('Copied Images'); console.info('Copied images');
fs.copyFileSync('./fonts/open_sans.woff2', './public/fonts/open_sans.woff2') fs.copyFileSync('./fonts/open_sans.woff2', './public/fonts/open_sans.woff2')
for (let file of glob.sync('./node_modules/font-awesome/fonts/*.*')) { for (let file of glob.sync('./node_modules/font-awesome/fonts/*.*')) {
@ -220,13 +243,14 @@ function bundleBinaryAssets() {
gzipFile(file); gzipFile(file);
} }
} }
console.info('Copied Fonts') console.info('Copied fonts')
} }
function bundleWebAppFiles() { function bundleWebAppFiles() {
const Jimp = require('jimp'); const Jimp = require('jimp');
fs.copyFileSync('./app/manifest.json', './public/manifest.json'); fs.writeFileSync('./public/manifest.json', JSON.stringify(app_manifest));
console.info('Generated app manifest');
Promise.all(webapp_icons.map(icon => { Promise.all(webapp_icons.map(icon => {
return Jimp.read('./img/app.png') return Jimp.read('./img/app.png')
@ -268,6 +292,7 @@ function makeOutputDirs() {
for (let dir of dirs) { for (let dir of dirs) {
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, 0o755); fs.mkdirSync(dir, 0o755);
console.info('Created directory: ' + dir);
} }
} }
} }