Skip to content

Commit

Permalink
fix: Relative URLs in pub-manifest are not resolved properly when the…
Browse files Browse the repository at this point in the history
… pub-manifest is linked from HTML elsewhere

Fixes #661
  • Loading branch information
MurakamiShinyu committed Sep 28, 2020
1 parent 9c5cbf5 commit b6fe7c1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/core/src/vivliostyle/epub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class EPUBDocStore extends OPS.OPSDocStore {
return;
}
const opf = new OPFDoc(this, url);
opf.initWithWebPubManifest(manifestObj).then(() => {
opf.initWithWebPubManifest(manifestObj, undefined, url).then(() => {
frame.finish(opf);
});
});
Expand Down Expand Up @@ -288,12 +288,16 @@ export class EPUBDocStore extends OPS.OPSDocStore {
frame.finish(opf);
});
} else {
this.loadAsJSON(
Base.resolveURL(manifestLink.getAttribute("href"), url),
).then((manifestObj) => {
opf.initWithWebPubManifest(manifestObj, doc).then(() => {
frame.finish(opf);
});
const manifestUrl = Base.resolveURL(
manifestLink.getAttribute("href"),
url,
);
this.loadAsJSON(manifestUrl).then((manifestObj) => {
opf
.initWithWebPubManifest(manifestObj, doc, manifestUrl)
.then(() => {
frame.finish(opf);
});
});
}
} else {
Expand Down Expand Up @@ -1154,6 +1158,7 @@ export class OPFDoc {
initWithWebPubManifest(
manifestObj: Base.JSON,
doc?: Document,
manifestUrl?: string,
): Task.Result<boolean> {
if (manifestObj["readingProgression"]) {
this.pageProgression = manifestObj["readingProgression"];
Expand Down Expand Up @@ -1225,7 +1230,10 @@ export class OPFDoc {
/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(url)
) {
const param = {
url: Base.resolveURL(Base.convertSpecialURL(url), this.pubURL),
url: Base.resolveURL(
Base.convertSpecialURL(url),
manifestUrl || this.pubURL,
),
index: itemCount++,
startPage: null,
skipPagesBefore: null,
Expand Down

0 comments on commit b6fe7c1

Please sign in to comment.