mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-11 10:46:15 +09:00
Merge pull request #158 from kbigdelysh/fix-windows-filename-error
Fix an error that preventing to save image files whose filenames ...
This commit is contained in:
+1
-1
@@ -122,7 +122,7 @@ function collectAttachedImages(allPostData) {
|
|||||||
// filter to certain image file types
|
// filter to certain image file types
|
||||||
.filter((attachment) => {
|
.filter((attachment) => {
|
||||||
const url = attachment.childValue('attachment_url');
|
const url = attachment.childValue('attachment_url');
|
||||||
return url && (/\.(gif|jpe?g|png|webp)$/i).test(url);
|
return url && (/\.(gif|jpe?g|png|webp)(\?|$)/i).test(url);
|
||||||
})
|
})
|
||||||
.map((attachment) => ({
|
.map((attachment) => ({
|
||||||
id: attachment.childValue('post_id'),
|
id: attachment.childValue('post_id'),
|
||||||
|
|||||||
@@ -73,6 +73,14 @@ export function buildPostPath(post, overrideConfig) {
|
|||||||
|
|
||||||
export function getFilenameFromUrl(url) {
|
export function getFilenameFromUrl(url) {
|
||||||
let filename = url.split('/').slice(-1)[0];
|
let filename = url.split('/').slice(-1)[0];
|
||||||
|
|
||||||
|
// Remove query parameters and hash fragments from filename
|
||||||
|
filename = filename.split('?')[0].split('#')[0];
|
||||||
|
|
||||||
|
// Replace any other invalid Windows filename characters
|
||||||
|
const invalidChars = /[<>:"\/\\|?*]/g;
|
||||||
|
filename = filename.replace(invalidChars, '_');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
filename = decodeURIComponent(filename)
|
filename = decodeURIComponent(filename)
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
|||||||
Reference in New Issue
Block a user