Skip to content

Commit

Permalink
✨ 新增 文章图片覆写
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaoo committed Mar 7, 2025
1 parent 41048b1 commit 6ad1b90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ function parseContent($content) {
<div class="post-timeline-content">${2}</div>
</div>';
$content = preg_replace($patt_timeline_item, $text_timeline_item, $content);
if (Helper::options()->isImageRewrite && in_array('open', Helper::options()->isImageRewrite)) {
$patt_img = '/<img(.*?)src="\.(.*?)"(.*?)>/s';
$imageURL = Helper::options()->imageRewriteUrl;
$text_image = '<img${1}src="'.$imageURL.'${2}"${3}>';
$content = preg_replace($patt_img, $text_image, $content);
}
echo $content;
}

Expand Down
6 changes: 4 additions & 2 deletions includes/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ function themeConfig($form) {
'local' => '本地',
'custom' => '自定义',
'dmoe.cc' => 'dmoe.cc'
], '随机文章图源', '在这里可以设置随机文章图源,仅当文章没有设置图片时引用。”', 'dmoe.cc').
$config->input('randimgCdn', '自定义随机文章图源', '在这里填写你自己的图源(如 api.xxx.xxx),以获取随机图片(需在上方选择自定义),若出现完全重复可以在结尾加上 ?rand={rand}').
], '随机文章封面图源', '在这里可以设置随机文章封面图源,仅当文章没有设置图片时引用。', 'dmoe.cc').
$config->input('randimgCdn', '自定义随机文章封面图源', '在这里填写你自己的图源(如 api.xxx.xxx),以获取随机图片(需在上方选择自定义),若出现完全重复可以在结尾加上 ?rand={rand}').
$config->checkbox('isImageRewrite', ['open' => '开启'], '文章图片覆写开关', '默认关闭,开启时将文章中的相对图片路径覆写为完整的URL路径(需填写 文章图片覆写 URL)', ['close']).
$config->input('imageRewriteUrl', '文章图片覆写 URL', '在这里填写 URL 以进行替换,URL 末尾无需带 "/"(具体请看主题文档)', '.').
$config->select('gravatar',
['cravatar' => 'Cravatar',
'weavatar' => 'WeAvatar',
Expand Down

0 comments on commit 6ad1b90

Please sign in to comment.