From 0edb7cdcbf7f1f79df363671fc1c94e13899de7e Mon Sep 17 00:00:00 2001 From: James Date: Sun, 17 May 2020 07:38:05 -0400 Subject: [PATCH 1/4] Add sane default if base element not found fix #1202 --- src/api/export.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/export.ts b/src/api/export.ts index 2779f0fd4..caa0930f7 100644 --- a/src/api/export.ts +++ b/src/api/export.ts @@ -186,7 +186,7 @@ async function _export({ const cleaned = clean_html(body); const base_match = //m.exec(cleaned); - const base_href = base_match && get_href(base_match[1]); + const base_href = base_match ? get_href(base_match[1]) : '/'; const base = resolve(url.href, base_href); let match; From 5833b461653146d696bdd7fa9466f4ac2d058e99 Mon Sep 17 00:00:00 2001 From: jamesjnadeau Date: Sun, 17 May 2020 07:48:50 -0400 Subject: [PATCH 2/4] Test basic .html file without base element --- test/apps/export/src/routes/index.svelte | 1 + test/apps/export/static/test.html | 13 +++++++++++++ test/apps/export/test.ts | 1 + 3 files changed, 15 insertions(+) create mode 100644 test/apps/export/static/test.html diff --git a/test/apps/export/src/routes/index.svelte b/test/apps/export/src/routes/index.svelte index 457298ad7..7b4c27d99 100644 --- a/test/apps/export/src/routes/index.svelte +++ b/test/apps/export/src/routes/index.svelte @@ -8,4 +8,5 @@ empty anchor #5 empty anchor #6 boom +html file pdf file \ No newline at end of file diff --git a/test/apps/export/static/test.html b/test/apps/export/static/test.html new file mode 100644 index 000000000..ea81abf9b --- /dev/null +++ b/test/apps/export/static/test.html @@ -0,0 +1,13 @@ + + + + + Page Title + + + +

Test Heading

+

Test Paragraph.

+ + + \ No newline at end of file diff --git a/test/apps/export/test.ts b/test/apps/export/test.ts index 850e38635..07c545274 100644 --- a/test/apps/export/test.ts +++ b/test/apps/export/test.ts @@ -41,6 +41,7 @@ describe('export', function() { 'index.html', 'service-worker-index.html', 'service-worker.js', + 'test.html', 'test.pdf', ...boom ].sort()); From 5a0ed4206479ecc86bfbfe8769a5e0034aca0b22 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 31 May 2020 07:16:55 -0400 Subject: [PATCH 3/4] Update src/api/export.ts thanks @thgh for pointing this out Co-authored-by: Thomas Ghysels --- src/api/export.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/export.ts b/src/api/export.ts index caa0930f7..0181e91e8 100644 --- a/src/api/export.ts +++ b/src/api/export.ts @@ -186,7 +186,7 @@ async function _export({ const cleaned = clean_html(body); const base_match = //m.exec(cleaned); - const base_href = base_match ? get_href(base_match[1]) : '/'; + const base_href = base_match ? get_href(base_match[1]) : url.pathname; const base = resolve(url.href, base_href); let match; From a0c2826a9cf5f4d89f984f85b0e90b75f3a99b54 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 31 May 2020 12:05:15 -0400 Subject: [PATCH 4/4] update default base path to use directory name instead of path per recommendation from @benmccann --- src/api/export.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/export.ts b/src/api/export.ts index 0181e91e8..ad77764f2 100644 --- a/src/api/export.ts +++ b/src/api/export.ts @@ -186,7 +186,7 @@ async function _export({ const cleaned = clean_html(body); const base_match = //m.exec(cleaned); - const base_href = base_match ? get_href(base_match[1]) : url.pathname; + const base_href = base_match ? get_href(base_match[1]) : path.dirname(url.pathname); const base = resolve(url.href, base_href); let match;