Skip to content

Commit 48c031e

Browse files
committed
Fixed the url of files in the images directory
1 parent c0935ac commit 48c031e

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

writing-on-github.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,28 @@ public function ignore_post_meta($meta) {
179179
public function the_content($content) {
180180
$arr = wp_upload_dir();
181181
$baseurl = $arr['baseurl'] . '/writing-on-github';
182+
$basedir = $arr['basedir'] . '/writing-on-github';
182183

183184
$content = preg_replace_callback(
184-
'/(<img [^>]*?src=[\'"])\s*(\/images\/[^\s#]\S+)\s*([\'"][^>]*?>)/',
185-
function($matchs) use ($baseurl) {
186-
$url = $baseurl . $matchs[2];
187-
return "${matchs[1]}$url${matchs[3]}";
185+
'/(<img [^>]*?src=[\'"])\S*?(\/images\/\S+)([\'"].*?>)/',
186+
function($matchs) use ($baseurl, $basedir) {
187+
if (is_file($basedir . $matchs[2])) {
188+
$url = $baseurl . $matchs[2];
189+
return "${matchs[1]}$url${matchs[3]}";
190+
}
191+
return "${matchs[0]}";
188192
},
189193
$content
190194
);
191195

192196
$content = preg_replace_callback(
193-
'/(<a [^>]*?href=[\'"])\s*(\/images\/[^\s#]\S+)\s*([\'"][^>]*?>)/',
194-
function($matchs) use ($baseurl) {
195-
$url = $baseurl . $matchs[2];
196-
return "${matchs[1]}$url${matchs[3]}";
197+
'/(<a [^>]*?href=[\'"])\S*?(\/images\/S+)\s*([\'"].*?>)/',
198+
function($matchs) use ($baseurl, $basedir) {
199+
if (is_file($basedir . $matchs[2])) {
200+
$url = $baseurl . $matchs[2];
201+
return "${matchs[1]}$url${matchs[3]}";
202+
}
203+
return "${matchs[0]}";
197204
},
198205
$content
199206
);

0 commit comments

Comments
 (0)