Skip to content

Commit cd1c97b

Browse files
committed
Enhance backward compatibility.
1 parent 6669e98 commit cd1c97b

File tree

11 files changed

+332
-298
lines changed

11 files changed

+332
-298
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ In all cases,
5454

5555

5656

57+
### Are you an user of BiB/i older than v1.0.0?
58+
59+
The folder structure and default public URL has changed in Bibi v1.0.0.
60+
But don't worry. You still can use not only the new style URL but also the same old style URL as before.
61+
62+
If you already published books on the web with BiB/i which version is older than v1.0.0, and want to update Bibi to v1.0.0 or newer, but do not want to change the public URLs of the books,
63+
64+
* Please download `Bibi-vX.Y.Z_with_BackCompatKit.zip`, and follow the document in it.
65+
66+
67+
5768
### Read in browsers on your local machine
5869

5970
1. Open `bibi/index.html` in your browser, and

__src/bibi/and/jo.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@
107107
const Bibi = Jo.Bibis[i];
108108
Bibi.move = (Distance) => {
109109
if(typeof Target != 'number') return;
110-
Bibi.Frame.contentWindow.postMessage(`{"bibi:commands:move":"${ Distance }"}`, Bibi.Anchor.origin);
110+
Bibi.Frame.contentWindow.postMessage(`{'bibi:commands:move':'${ Distance }'}`, Bibi.Anchor.origin);
111111
};
112112
Bibi.focus = (Target) => {
113113
if(typeof Target != 'string' && typeof Target != 'number') return;
114-
Bibi.Frame.contentWindow.postMessage(`{"bibi:commands:focus":"${ Target }"}`, Bibi.Anchor.origin);
114+
Bibi.Frame.contentWindow.postMessage(`{'bibi:commands:focus':'${ Target }'}`, Bibi.Anchor.origin);
115115
};
116116
Bibi.changeView = (BDM) => {
117-
if(typeof Target != "string") return;
118-
Bibi.Frame.contentWindow.postMessage(`{"bibi:commands:change-view":"${ BDM }"}`, Bibi.Anchor.origin);
117+
if(typeof Target != 'string') return;
118+
Bibi.Frame.contentWindow.postMessage(`{'bibi:commands:change-view':'${ BDM }'}`, Bibi.Anchor.origin);
119119
};
120120
Bibi.togglePanel = () => {
121-
Bibi.Frame.contentWindow.postMessage(`{"bibi:command:toggle-panel":""}`, Bibi.Anchor.origin);
121+
Bibi.Frame.contentWindow.postMessage(`{'bibi:command:toggle-panel':''}`, Bibi.Anchor.origin);
122122
};
123123
Bibi.Anchor.style.display = 'none';
124124
Bibi.Anchor.parentNode.insertBefore(Bibi.Holder, Bibi.Anchor);

__src/bibi/resources/styles/_panel.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ div#bibi-panel-bookinfo-cover {
225225
line-height: 1.2;
226226
margin: 0 0 .5rem 0;
227227
span {
228-
display: inline-block;
228+
//display: inline-block;
229229
}
230230
}
231231
> strong {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
3+
[en] How to use the same URLs as before v1.0.0 to publish books on the web.
4+
================================================================================================
5+
6+
The folder structure has changed in Bibi v1.0.0, and the URL for publishing books has changed accordingly.
7+
But don't worry. You still can use not only the new style URL but also the same style URL as before.
8+
9+
Please try this way, if you already have publicated books on the web with BiB/i older than v1.0.0, and want to update Bibi to newer version, but do not want to or can not change the public URLs of the books.
10+
11+
1. At first, upload the new "bibi" folder to the same directory of the "bib" directory on your web server.
12+
2. Next, Replace "index.html" file in the "bib/i" directory on your web server with the one in the new "bib/i" folder (If you haven't customized the "index.html" file, you can simply overwrite with new one).
13+
14+
Just by that, your Bibi is updated to v1.0.0, and ready to open your books via the same "https://your.server/bib/i/?book=***" style URL as before. There's no need to move EPUB data out of the "bib/bookshelf" directory.
15+
What's more, you can also use the new "https://your.server/bibi/?book=****" style URL to open books stored in the "bibi-bookshelf" directory (this is the default method since Bibi v1.0.0).
16+
17+
If you interested in more info, read below too:
18+
* The same new "bibi/presets/default.js" preset file is used in both old and new style URLs.
19+
* If your old BiB/i is using customized old "bib/i/presets/default.js" preset file, and you want new Bibi to behave same as before, edit options one by one in the new preset file (Because the options in the preset file are renewed).
20+
* You can use different preset file in each HTML by editing "src" attribute of script#bibi-preset element.
21+
* You can change the path to the bookshelf directory by editing HTML or the preset file. The data-bibi-bookshelf attribute of script#bibi-preset element in HTML is prior than "bookshelf" option in the preset file.
22+
* By combining these, various ways of installation and operation are possibles (for example, having share the same bookshelf directory with both old and new style URLs, or using different HTML or preset files for each book).
23+
24+
25+
--------------------------------------------------------------------------------------------------------------------------------
26+
27+
28+
[ja] v1.0.0 以前と同じ URL で、書籍をウェブ公開するには
29+
================================================================================================
30+
31+
Bibi v1.0.0 でフォルダー構造が変更され、それに伴って書籍を発行するための URL も変更されました。
32+
でもご安心を。新スタイルの URL だけでなく、これまでどおり旧スタイルの URL も使用できます。
33+
34+
もし、既に v1.0.0 よりも古い BiB/i で書籍をウェブ公開していて、Bibi は新しいバージョンに更新したいけれど、書籍の公開 URL は変更したくない・できない、というときは、この方法を試してください。
35+
36+
1. まず、新しい「bibi」フォルダを、ウェブサーバ上の「bib」ディレクトリと同じディレクトリにアップロードします。
37+
2. 次に、ウェブサーバ上の「bib/i」ディレクトリにある「index.html」ファイルを、新しい「bib/i」フォルダ内にある「index.html」に交換します(「index.html」ファイルをカスタマイズしていなければ、単純に上書きしてかまいません)。
38+
39+
それだけで、Bibi は v1.0.0 に更新され、以前と同じ「https://your.server/bib/i/?book=***」形式の URL で本を開けるようになります。EPUB データを「bib/bookshelf」ディレクトリから移動する必要もありません。
40+
しかも、新しい「https://your.server/bibi/?book=****」形式の URL を使用して「bibi-bookshelf」ディレクトリに保存された本を開くこともできます(これは、Bibi v1.0.0 以降のデフォルトの方法です)。
41+
42+
もし、より詳細な情報に興味があれば、以下もお読みください。
43+
* 新しい「bibi/presets/default.js」プリセットファイルが、新旧両スタイルの URL で使用されます。
44+
* 古い BiB/i がカスタマイズされた古い「bib/i/presets/default.js」プリセットファイルを使用していて、新しい Bibi にも同じように振る舞ってほしい場合は、新しいプリセットファイルでオプションを1つずつ編集してください(プリセットファイルのオプションが新しくなっているためです)。
45+
* script#bibi-preset 要素の src 属性を編集することにより、各 HTML で異なるプリセットファイルを使用できます。
46+
* HTML またはプリセットファイルを編集して、bookshelf ディレクトリへのパスを変更できます。HTMLの script#bibi-preset 要素の data-bibi-bookshelf 属性は、プリセットファイルの "bookshelf" オプションよりも優先されます。
47+
* これらを組み合わせることで、多様な設置・運用方法が可能になります(たとえば、同じ bookshelf ディレクトリを新旧両スタイルの URL で共有したり、開く本ごとに異なる HTML やプリセットを用意したり)。

__src__back-compat/bib/i.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('../../__src/bibi/and/jo.js');

__src__back-compat/bib/i/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<link id="bibi-style" rel="stylesheet" href="../../bibi/resources/styles/bibi.css" />
2424
<link id="bibi-dress" rel="stylesheet" href="../../bibi/wardrobe/everyday/bibi.dress.css" />
2525
<script id="bibi-script" src="../../bibi/resources/scripts/bibi.js"></script>
26-
<script id="bibi-preset" src="../../bibi/presets/default.js" data-bibi-bookshelf=""></script>
26+
<script id="bibi-preset" src="../../bibi/presets/default.js" data-bibi-bookshelf="../bookshelf"></script>
2727

2828
</head>
2929

bibi.info.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ const Bibi = {
1515
'homepage': 'https://bibi.epub.link or https://github.com/satorumurmur/bibi'
1616
};
1717

18+
Bibi.Arguments = (() => {
19+
const KRE = /^\-+([\w\d_\-]+)$/;
20+
let CurrentKey = null;
21+
return process.argv.reduce((As, KoV) => {
22+
if(KRE.test(KoV)) CurrentKey = KoV.replace(KRE, '$1'), As[CurrentKey] = true;
23+
else if(CurrentKey) As[CurrentKey] = KoV, CurrentKey = null;
24+
return As;
25+
}, {});
26+
})();
27+
28+
Bibi.ForPack = (Bibi.Arguments['pack']);
29+
Bibi.WithBCK = (Bibi.Arguments['bc'] || Bibi.ForPack);
30+
1831
// =============================================================================================================================
1932

2033
const _banner = (Name, Credit, Extra, Mark) => '/*!' + `
@@ -81,7 +94,8 @@ Bibi.Banners = {
8194

8295
// -----------------------------------------------------------------------------------------------------------------------------
8396

84-
'/jo.js': _banner(`Jo | Helper for Embedding Bibi-Frames in Webpage.`, 'default', null, true),
97+
'/and/jo.js': _banner(`Jo | Helper for Embedding Bibi-Frames in Webpage.`, 'default', null, true),
98+
'^bib/i.js': _banner(`Jo | Helper for Embedding Bibi-Frames in Webpage.`, 'default', null, true),
8599

86100
// -----------------------------------------------------------------------------------------------------------------------------
87101

@@ -124,7 +138,7 @@ Bibi.Banners = {
124138

125139
// =============================================================================================================================
126140

127-
Bibi.ARCHIVES = '__archives', Bibi.DIST = '__dist', Bibi.SRC = '__src', Bibi.SRCBC = '__src__back-compat';
141+
Bibi.ARCHIVES = '__archives', Bibi.ARCHIVETMP = Bibi.ARCHIVES + '/.tmp', Bibi.DIST = '__dist', Bibi.SRC = '__src', Bibi.SRCBC = '__src__back-compat';
128142

129143
// =============================================================================================================================
130144

gulpfile.js

Lines changed: 78 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -7,163 +7,98 @@
77
'use strict';
88

99
const gulp = require('gulp'), del = require('del'), fs = require('fs'), rename = require('gulp-rename'), zip = require('gulp-zip');
10-
const Package = JSON.parse(fs.readFileSync('package.json')), Bibi = require('./bibi.info.js');
1110

12-
const PackageName = Package.name == 'bibi' ? 'Bibi' : Package.name;
11+
const Package = JSON.parse(fs.readFileSync('package.json'));
12+
const Bibi = require('./bibi.info.js');
1313

14-
/* initialize */ {
15-
gulp.task('initialize', done => {
16-
fs.mkdirSync(Bibi.DIST + '/bibi', { recursive: true });
17-
fs.mkdirSync(Bibi.DIST + '/bibi-bookshelf', { recursive: true }); done();
14+
gulp.task('clean', done => {
15+
del.sync([
16+
'**/.DS_Store',
17+
'**/Thumbs.db',
18+
'LICENSE',
19+
'*.md',
20+
'bibi/*.html',
21+
'bibi/and',
22+
'bibi/extensions',
23+
'bibi/presets',
24+
'bibi/resources',
25+
'bibi/wardrobe',
26+
'bib/i/*.html',
27+
'bib/i.js',
28+
'bib/i/presets'
29+
].map(
30+
X => Bibi.DIST + '/' + X
31+
));
32+
[
33+
'bibi',
34+
'bibi-bookshelf',
35+
'bib/i',
36+
//'bib/bookshelf',
37+
'bib'
38+
].forEach(Dir => {
39+
try { Dir = Bibi.DIST + '/' + Dir ; if(!fs.readdirSync(Dir).length) del.sync(Dir); } catch(E) {}
1840
});
19-
}
41+
del.sync(Bibi.ARCHIVETMP);
42+
done();
43+
});
2044

21-
/* clean */ {
22-
gulp.task('clean', done => {
23-
del.sync([
24-
'**/.DS_Store',
25-
'**/Thumbs.db',
26-
'bibi/LICENSE',
27-
'bibi/README.md',
28-
'bibi/*.html',
29-
'bibi/and',
30-
'bibi/extensions',
31-
'bibi/presets',
32-
'bibi/resources',
33-
'bibi/wardrobe',
34-
'bib/i/*.html',
35-
'bib/i.js'
36-
].map(
37-
X => Bibi.DIST + '/' + X
38-
));
39-
try { if(!fs.readdirSync(Bibi.DIST + '/bibi' ).length) del.sync(Bibi.DIST + '/bibi' ); } catch(E) {}
40-
try { if(!fs.readdirSync(Bibi.DIST + '/bib/i').length) del.sync(Bibi.DIST + '/bib/i'); } catch(E) {}
41-
try { if(!fs.readdirSync(Bibi.DIST + '/bib' ).length) del.sync(Bibi.DIST + '/bib' ); } catch(E) {}
42-
done();
45+
gulp.task('initialize', done => {
46+
[
47+
'bibi',
48+
'bibi-bookshelf'
49+
].concat(Bibi.WithBCK ? [
50+
'bib',
51+
'bib/i',
52+
//'bib/bookshelf'
53+
] : []).forEach(Dir => {
54+
fs.mkdirSync((Bibi.ForPack ? Bibi.ARCHIVETMP : Bibi.DIST) + '/' + Dir, { recursive: true });
4355
});
44-
}
56+
done();
57+
});
4558

46-
/* make:backward-compatibility-kit-files, clean:backward-compatibility-kit-files */ {
47-
gulp.task('make:backward-compatibility-kit:bib/i/*.html', () => {
48-
return gulp.src([
49-
Bibi.SRCBC + '/bib/i/*.html'
50-
], {
51-
base: Bibi.SRCBC
52-
}).pipe(gulp.dest(
53-
Bibi.DIST
54-
));
55-
});
56-
gulp.task('make:backward-compatibility-kit:bib/i.js', () => {
57-
return gulp.src([
58-
Bibi.DIST + '/bibi/and/jo.js'
59-
], {
60-
base: Bibi.DIST
61-
}).pipe(rename(
62-
'bib/i.js'
63-
)).pipe(gulp.dest(
64-
Bibi.DIST
65-
));
66-
});
67-
gulp.task('make:backward-compatibility-kit-files', gulp.parallel(
68-
'make:backward-compatibility-kit:bib/i/*.html',
69-
'make:backward-compatibility-kit:bib/i.js'
70-
));
71-
gulp.task('clean:backward-compatibility-kit-files', done => {
72-
del.sync([
73-
'bib/**/.DS_Store',
74-
'bib/**/Thumbs.db',
75-
'bib/i/*.html',
76-
'bib/i.js'
77-
].map(
78-
X => Bibi.DIST + '/' + X
79-
));
80-
try { if(!fs.readdirSync(Bibi.DIST + '/bib/i').length) del.sync(Bibi.DIST + '/bib/i'); } catch(E) {}
81-
try { if(!fs.readdirSync(Bibi.DIST + '/bib' ).length) del.sync(Bibi.DIST + '/bib' ); } catch(E) {}
82-
done();
83-
});
84-
}
59+
gulp.task('reset', gulp.series(
60+
'clean',
61+
'initialize'
62+
));
8563

86-
const setPackageBuilderTasks = (Opt) => {
87-
gulp.task('clean:' + Opt.Name + '-archive', done => {
88-
del.sync([
89-
Bibi.ARCHIVES + '/' + Opt.Label + '.zip'
90-
]);
91-
done();
92-
});
93-
gulp.task('clean:' + Opt.Name + '-directory', done => {
94-
del.sync([
95-
Bibi.ARCHIVES + '/' + Opt.Label
96-
]);
97-
done();
98-
});
99-
gulp.task('merge:' + Opt.Name + '-content', () => {
100-
if(Opt.Bookshelf) fs.mkdirSync(Bibi.ARCHIVES + '/' + Opt.Label + '/' + Opt.Bookshelf, { recursive: true });
101-
return gulp.src(Opt.Files.map(
102-
X => Bibi.DIST + '/' + X
103-
), {
104-
base: Bibi.DIST
105-
}).pipe(gulp.dest(
106-
Bibi.ARCHIVES + '/' + Opt.Label
107-
));
108-
});
109-
gulp.task('zip:' + Opt.Name, () => {
110-
return gulp.src([
111-
Bibi.ARCHIVES + '/' + Opt.Label + '/**'
112-
], {
113-
base: Bibi.ARCHIVES
114-
}).pipe(zip(
115-
Opt.Label + '.zip'
116-
)).pipe(gulp.dest(
117-
Bibi.ARCHIVES
118-
));
119-
});
120-
gulp.task('make:' + Opt.Name + '-archive', gulp.series(
121-
gulp.parallel(
122-
'clean:' + Opt.Name + '-directory',
123-
'clean:' + Opt.Name + '-archive'
124-
),
125-
'merge:' + Opt.Name + '-content',
126-
'zip:' + Opt.Name,
127-
'clean:' + Opt.Name + '-directory'
64+
gulp.task('make:dress-template', () => {
65+
return gulp.src([
66+
Bibi.SRC + '/bibi/wardrobe/_dress-codes/**',
67+
], {
68+
base: Bibi.SRC + '/bibi/wardrobe/_dress-codes'
69+
}).pipe(gulp.dest(
70+
Bibi.SRC + '/bibi/wardrobe/DRESS-TEMPLATE-' + new Date(Date.now() + 1000 * 60 * 60 * (new Date().getTimezoneOffset() / -60)).toISOString().split('.')[0].replace(/[-:]/g, '').replace('T', '-')
12871
));
129-
};
72+
});
13073

131-
/* make:distribution-package-archive */
132-
setPackageBuilderTasks({
133-
Name: 'distribution-package',
134-
Label: PackageName + '-v' + Package.version,
135-
Bookshelf: 'bibi-bookshelf',
136-
Files: [
137-
'bibi/LICENSE',
138-
'bibi/README.md',
74+
gulp.task('make:package', () => {
75+
const PackageName = (Package.name == 'bibi' ? 'Bibi' : Package.name) + '-v' + Package.version + (Bibi.WithBCK ? '_with_BackCompatKit' : '') + '.zip';
76+
del.sync([
77+
Bibi.ARCHIVES + '/' + PackageName
78+
]);
79+
return gulp.src([
80+
'LICENSE',
81+
'README.md',
13982
'bibi/*.html',
14083
'bibi/and/**',
14184
'bibi/extensions/**',
14285
'bibi/presets/**',
14386
'bibi/resources/**',
14487
'bibi/wardrobe/**',
145-
]
146-
});
147-
148-
/* make:backward-compatibility-kit-archive */
149-
setPackageBuilderTasks({
150-
Name: 'backward-compatibility-kit',
151-
Label: PackageName + '-v' + Package.version + '_BackCompatKit',
152-
//Bookshelf: 'bib/bookshelf',
153-
Files: [
88+
'bibi-bookshelf'
89+
].concat(Bibi.WithBCK ? [
90+
'README.BackCompatKit.md',
15491
'bib/i/*.html',
155-
'bib/i.js'
156-
]
92+
'bib/i.js',
93+
'bib/i/presets/**',
94+
//'bib/bookshelf'
95+
] : []).map(
96+
X => Bibi.ARCHIVETMP + '/' + X
97+
), {
98+
base: Bibi.ARCHIVETMP
99+
}).pipe(zip(
100+
PackageName
101+
)).pipe(gulp.dest(
102+
Bibi.ARCHIVES
103+
));
157104
});
158-
159-
/* make:dress-template */ {
160-
gulp.task('make:dress-template', () => {
161-
return gulp.src([
162-
Bibi.SRC + '/bibi/wardrobe/_dress-codes/**',
163-
], {
164-
base: Bibi.SRC + '/bibi/wardrobe/_dress-codes'
165-
}).pipe(gulp.dest(
166-
Bibi.SRC + '/bibi/wardrobe/DRESS-TEMPLATE-' + new Date(Date.now() + 1000 * 60 * 60 * (new Date().getTimezoneOffset() / -60)).toISOString().split('.')[0].replace(/[-:]/g, '').replace('T', '-')
167-
));
168-
});
169-
}

0 commit comments

Comments
 (0)