Skip to content

Commit 5ead07a

Browse files
committed
Squashed 'AMP/' changes from 02792f1..c7057a2
c7057a2 optimizational function. For issues https://holmesian.org/AMP-for-Typecho#comment-7425. git-subtree-dir: AMP git-subtree-split: c7057a2c2f637b4722c74b167c3b1e1dcd75f95c
1 parent 36f0a58 commit 5ead07a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Action.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function getArticle($target)
267267
$tempTarget = explode('.', $target)[0];
268268
$article = $this->getArticleBySlug($tempTarget);
269269
if (isset($article['isblank'])) {
270-
$article = $article = $this->getArticleByCid($tempTarget);
270+
$article = $this->getArticleByCid($tempTarget);
271271
}
272272
return $article;
273273
}
@@ -366,8 +366,9 @@ public function MakeArticleList($linkType = 'amp', $page = 0, $pageSize = 0)
366366

367367
private function GetPostImg()
368368
{
369+
369370
$text = $this->article['text'];
370-
371+
371372
$pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i';
372373
$patternMD = '/\!\[.*?\]\((http(s)?:\/\/.*?(jpg|png))/i';
373374
$patternMDfoot = '/\[.*?\]:\s*(http(s)?:\/\/.*?(jpg|png))/i';
@@ -379,8 +380,21 @@ private function GetPostImg()
379380
preg_match("/(?:\()(.*)(?:\))/i", $img[0], $result);
380381
$img_url = $img[1];
381382
} else {
382-
$img_url = $this->defaultPIC;
383+
//正文里没找到图片就去附件里找
384+
$attsrc=Typecho_Widget::widget('Widget_Contents_Attachment_Related', 'parentId=' . $this->article['cid'])->stack;
385+
$att='';
386+
foreach ($attsrc as $attimg){
387+
$att=$att.$attimg['text'];
388+
}
389+
if (preg_match($pattern, $att, $img)) {//附件里只需要匹配img标签的内容
390+
preg_match("/(?:\()(.*)(?:\))/i", $img[0], $result);
391+
$img_url = $img[1];
392+
}else{//附件里再找不到就调LOGO了
393+
$img_url = $this->defaultPIC;
394+
}
383395
}
396+
397+
384398
try {
385399
list($width, $height, $type, $attr) = @getimagesize($img_url);
386400
$imgData=array(

Plugin.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
*
55
* @package AMP-MIP
66
* @author Holmesian
7-
* @version 0.6.0
7+
* @version 0.6.1
88
* @link https://holmesian.org
99
*/
1010
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
1111

1212
class AMP_Plugin implements Typecho_Plugin_Interface
1313
{
14-
private static $version = '0.6.0';
14+
private static $version = '0.6.1';
1515

1616
public static function activate()
1717
{

0 commit comments

Comments
 (0)