插件Typecho-AMP源码完全解析 - 下篇
上篇我们介绍了一下typecho-插件的主题部分,主要是常规的插件操作以及激活后的回调。这一篇我们将讲述一些附加的功能。
Links.php
<?php
error_reporting(E_ALL);
include 'header.php';
include 'menu.php';
date_default_timezone_set('PRC');
$user = Typecho_Widget::widget('Widget_User');
if(!$user->pass('administrator')){
die('未登录用户!');
}
if (isset($_GET['send'])) {
$http = Typecho_Http_Client::get();
$db = Typecho_Db::get();
//URL分页
if (isset($_GET['page'])) {
$page = (int)($_GET['page']);
} else {
$page = 1;
}
//URL类型
if ((isset($_GET['type']) and $_GET['type'] == 'amp') OR (isset($_POST['type']) and $_POST['type'] == 'amp')) {
$sendtype = 'amp';
$type = 'amp';
} elseif ((isset($_GET['type']) and $_GET['type'] == 'mip') OR (isset($_POST['type']) and $_POST['type'] == 'mip')) {
$sendtype = 'mip';
$type = 'mip';
} elseif ((isset($_GET['type']) and $_GET['type'] == 'batch') OR (isset($_POST['type']) and $_POST['type'] == 'batch')) {
$sendtype = 'mip';
$type = 'batch';
if (isset(Helper::options()->plugin('AMP')->baiduAPPID) and isset(Helper::options()->plugin('AMP')->baiduTOKEN)) {
$appid = Helper::options()->plugin('AMP')->baiduAPPID;
$token = Helper::options()->plugin('AMP')->baiduTOKEN;
$api = "http://data.zz.baidu.com/urls?appid={$appid}&token={$token}&type=batch";
} else {
throw new Typecho_Widget_Exception('未设置熊掌号参数!');
}
} else {
$sendtype = 'mip';
$type = 'mip';
}
$articleList = Typecho_Widget::widget('AMP_Action')->MakeArticleList($sendtype, $page, 20);
//接口类型
if (!isset($api)) {
if (empty(Helper::options()->plugin('AMP')->baiduAPI)) {
throw new Typecho_Widget_Exception('未设置MIP/AMP推送接口调用地址!');
} else {
$api = Helper::options()->plugin('AMP')->baiduAPI;
$api = preg_replace("/&type=[a-z]+/", "&type={$sendtype}", $api);//替换接口中的类型
}
}
$urls = array();
foreach ($articleList AS $article) {
if(Helper::options()->plugin('AMP')->PostURL !== Helper::options()->index){
$article['permalink']=str_replace(Helper::options()->index,Helper::options()->plugin('AMP')->PostURL,$article['permalink']);//替换提交的前缀
}
echo '正在提交:' . $article['permalink'] . " <br>";
$urls[] = $article['permalink'];
}
if (count($urls) > 0) {
$http->setData(implode("\n", $urls));
$http->setHeader('Content-Type', 'text/plain');
try {
$result = $http->send($api);
} catch (Exception $e) {
throw new Typecho_Plugin_Exception(_t('对不起, 您的主机不支持远程访问。<br>请检查 curl 扩展、allow_url_fopen和防火墙设置!<br><hr>出错信息:'.$e->getMessage()));
}
// string '{"remain":4999960,"success":0,"not_valid":[""]}'
// string '{"success_mip":20,"remain_mip":9980}' (length=36)
// $result='{"success_amp":20,"remain_amp":9980}';
// string(43) "{"success_batch":20,"remain_batch":4999960}"
$obj = json_decode($result, true);
$name = "success_{$type}";
if (isset($obj[$name])) {
echo '<hr>';
echo "第{$page}页提交成功,";
$count = $obj["remain_{$type}"];
echo "还可提交{$count}条URL,准备提交下一页>>>";
$page += 1;
?>
<script language="JavaScript">
window.setTimeout("location='<?php $options->adminUrl('extending.php?panel=AMP/Links.php' . "&send=1&type={$type}&page={$page}");
?>'", 2000);
</script>
未自动跳转请点击<a
href="<?php $options->adminUrl('extending.php?panel=AMP/Links.php' . "&send=1&type={$type}&page={$page}"); ?>">这里</a>
<?php
} else {
echo "<hr>错误提示:";
print_r($obj);
echo "<br>提交失败,请检查提交地址。如有必要,请将错误提示<a href='https://github.com/holmesian/Typecho-AMP/issues'>反馈给作者</a>";
}
} else {
echo "已全部提交完成";
?>
<script language="JavaScript">
window.setTimeout("location='<?php $options->adminUrl('extending.php?panel=AMP/Links.php');?>'", 2000);
</script>
未自动跳转请点击<a href="<?php $options->adminUrl('extending.php?panel=AMP/Links.php'); ?>">这里</a>
<?php
}
} else {
?>
<div class="main">
<div class="body container">
<?php include 'page-title.php'; ?>
<div class="row typecho-page-main" role="main">
<form action="<?php $options->adminUrl('extending.php?panel=AMP/Links.php&send=1'); ?>" method="POST">
<div class="operate" style="text-align: center;">
<select name="type" style="width:200px;text-align-last: center;">
<option value="amp">AMP</option>
<option value="mip">MIP</option>
<option value="batch">熊掌号</option>
</select>
<button type="submit" class="btn btn-s"><?php _e('开始提交'); ?></button>
</div>
</form>
<div>
<p>1.AMP(Accelerated Mobile
Pages),是谷歌的一项开放源代码计划,可在移动设备上快速加载的轻便型网页,旨在使网页在移动设备上快速加载并且看起来非常美观。选择该项为自动向百度提交AMP页面地址。</p>
<p>2.MIP(Mobile Instant Page -
移动网页加速器),是一套应用于移动网页的开放性技术标准。通过提供MIP-HTML规范、MIP-JS运行环境以及MIP-Cache页面缓存系统,实现移动网页加速。选择该项为自动向百度提交页面地址。</p>
<p>
3.熊掌号,是百度熊掌号是内容和服务提供者入驻百度生态的实名账号。通过历史内容接口,每天可提交最多500万条有价值的内容,所提交内容会进入百度搜索统一处理流程。请先设置好APPID和TOKEN后再进行提交。</p>
<p></p>
<p><b>如果因服务器环境无法自动提交</b>,可打开<a target="_blank"
href="<?php print(Helper::options()->index . '/amp_sitemap.xml?txt=1'); ?>">AMP网址列表</a>、<a
target="_blank"
href="<?php print(Helper::options()->index . '/mip_sitemap.xml?txt=1'); ?>">MIP网址列表</a>,手动复制URL提交到百度站长后台。
</p>
</div>
</div><!-- end .typecho-page-main -->
</div>
</div>
<?php
}
include 'copyright.php';
include 'common-js.php';
include 'table-js.php';
?>
<?php
include 'footer.php';
?>
Links.php的功能就是当触发提交mip或者amp链接到百度的时候,呈现一个页面给读者。上面有各种动态信息和成功以及失败的理由。
还要承担将数据提交(send)给百度的熊掌号。
templates 模板 - AMPindex.php
<!doctype html>
<html amp lang="zh">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
<title><?php echo(Helper::options()->title." -- AMP Version"); ?></title>
<link rel="canonical" href="<?php echo($this->baseurl); ?>"/>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-custom>*{margin:0;padding:0}html,body{height:100%}body{background:#fff;color:#666;font-size:14px;font-family:"-apple-system","Open Sans","HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,sans-serif}::selection,::-moz-selection,::-webkit-selection{background-color:#2479cc;color:#eee}h1{font-size:1.5em}h3{font-size:1.3em}h4{font-size:1.1em}a{color:#2479cc;text-decoration:none}header{background-color:#fff;box-shadow:0 0 40px 0 rgba(0,0,0,0.1);box-sizing:border-box;font-size:14px;height:60px;padding:0 15px;position:absolute;width:100%}header a{color:#333}header h1{font-size:30px;font-weight:400;line-height:30px;margin:15px 0}footer{font-size:.9em;text-align:center;width:auto;padding: 10px;}.content{padding-top:60px}article{position:relative;padding:30px;border-top:1px solid #fff;border-bottom:1px solid #ddd}.pageinfo{font-size:15px;padding:5px;margin:5px;text-align:center}.info{background-color:#f5d09a;border:1px solid #e2e2e2;border-left:5px solid #fff000;color:#333;font-size:15px;padding:5px 10px;margin:10px 0}.nav{text-align:center;margin-bottom:-25px}.nav button{width:150px;height:25px;margin:auto;margin-bottom:20px;border-width:0;border-radius:3px;background:#1e90ff;cursor:pointer;outline:0;color:white;font-size:16px}button:hover{background:#59f}article a{font-size:2em}article p{position:relative;line-height:2em;font-size:16px;text-indent:2em;padding-top:15px}</style>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>
<header>
<div class="header-title"><h1><a href="<?php echo($this->baseurl); ?>"><?php echo(Helper::options()->title);?></a></h1></div>
</header>
<div></div>
<div class="content">
<amp-list width="auto"
height="650"
layout="fixed-height"
src="<?php echo Typecho_Common::url("amp/list/1", $this->baseurl);?>"
[src]="'<?php echo Typecho_Common::url("amp/list/", $this->baseurl);?>' + pageNumber"
single-item>
<template type="amp-mustache">
{{#article}}
<article>
<a href="{{url}}">{{title}}</a>
<div class="article_content"><p>{{content}}</p></div>
</article>
{{/article}}
<p class="pageinfo">Page {{currentPage}} of {{pageCount}} </p>
</template>
</amp-list>
</div>
<footer>
<div class="nav">
<button class="prev"
hidden
[hidden]="pageNumber < 2"
on="tap:
AMP.setState({
pageNumber: pageNumber - 1
})">Previous</button>
<button class="next"
[hidden]="page ? pageNumber >= page.items.pageCount : false"
on="tap:
AMP.setState({
pageNumber: pageNumber ? pageNumber + 1 : 2
})">Next</button>
</div>
<amp-state id="page"
src="<?php echo Typecho_Common::url("amp/list/1", $this->baseurl);?>"
[src]="'<?php echo Typecho_Common::url("amp/list/", $this->baseurl);?>' + pageNumber"></amp-state>
<div><p class="info">当前页面是本站的「<a href="//www.ampproject.org/zh_cn/">Google AMP</a>」版。查看和发表评论请点击:<a
href="<?php echo($this->baseurl); ?>">完整版 »</a></p></div>
<div class="footer"><p>© 2018 <a data-type="amp" href="https://github.com/holmesian/Typecho-AMP">AMP for Typecho</a> v<?php echo(AMP_Plugin::$version); ?>
, Designed by <a href="https://holmesian.org/" target="_blank">Holmesian</a>.</p></div>
</footer>
</body>
</html>
主页amp格式的模板,想修改主页的amp样式可以在这里修改。
AMPpage.php
<!doctype html>
<html amp lang="zh">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title><?php echo($AMPpage['title']); ?></title>
<link rel="canonical" href="<?php echo($AMPpage['permalink']); ?>"/>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"headline": "<?php echo($AMPpage['title']); ?>",
"mainEntityOfPage": "<?php echo($AMPpage['permalink']); ?>",
"author": {
"@type": "Person",
"name": "<?php echo($AMPpage['author']); ?>"
},
"datePublished": "<?php echo($AMPpage['date']); ?>",
"dateModified": "<?php echo($AMPpage['modified']); ?>",
"image": {
"@type": "ImageObject",
"url": "<?php echo($AMPpage['imgData']['url']); ?>",
"width": "<?php echo($AMPpage['imgData']['width']); ?>",
"height": "<?php echo($AMPpage['imgData']['height']); ?>"
},
"publisher": {
"@type": "Organization",
"name": "<?php echo($AMPpage['publisher']); ?>",
"logo": {
"@type": "ImageObject",
"url": "<?php echo($AMPpage['LOGO']); ?>",
"width": 60,
"height": 60
}
},
"description": "<?php echo($AMPpage['desc']); ?>"
}
</script>
<style amp-custom>*{margin:0;padding:0}html,body{height:100%}body{background:#fff;color:#666;font-size:14px;font-family:"-apple-system","Open Sans","HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,sans-serif}::selection,::-moz-selection,::-webkit-selection{background-color:#2479CC;color:#eee}h1{font-size:1.5em}h3{font-size:1.3em}h4{font-size:1.1em}a{color:#2479CC;text-decoration:none}article{padding:85px 15px 0}article .entry-content{color:#444;font-size:16px;font-family:Arial,'Hiragino Sans GB',冬青黑,'Microsoft YaHei',微软雅黑,SimSun,宋体,Helvetica,Tahoma,'Arial sans-serif';-webkit-font-smoothing:antialiased;line-height:1.8;word-wrap:break-word}article h1.title{color:#333;font-size:2em;font-weight:300;line-height:35px;margin-bottom:25px}article .entry-content p{margin-top:15px;text-indent: 2em;}article h1.title a{color:#333;transition:color .3s}article h1.title a:hover{color:#2479CC}article blockquote{background-color:#f8f8f8;border-left:5px solid #2479CC;margin-top:10px;overflow:hidden;padding:15px 20px}article code{background-color:#eee;border-radius:5px;font-family:Consolas,Monaco,'Andale Mono',monospace;font-size:80%;margin:0 2px;padding:4px 5px;vertical-align:middle}article pre{background-color:#f8f8f8;border-left:5px solid #ccc;color:#5d6a6a;font-size:14px;line-height:1.6;overflow:hidden;padding:0.6em;position:relative;white-space:pre-wrap;word-break:break-word;word-wrap:break-word}article table{border:0;border-collapse:collapse;border-spacing:0}article pre code{background-color:transparent;border-radius:0 0 0 0;border:0;display:block;font-size:100%;margin:0;padding:0;position:relative}article table th,article table td{border:0}article table th{border-bottom:2px solid #848484;padding:6px 20px;text-align:left}article table td{border-bottom:1px solid #d0d0d0;padding:6px 20px}article .copyright-info,article .amp-info{font-size:14px}article .notice{background-color:#f5d09a;border:1px solid #e2e2e2;border-left:5px solid #fff000;color:#333;font-size:15px;padding:5px 10px;margin:20px 0px}article .post-info,article .entry-content .date{font-size:14px}article .entry-content blockquote,article .entry-content ul,article .entry-content ol,article .entry-content dl,article .entry-content table,article .entry-content h1,article .entry-content h2,article .entry-content h3,article .entry-content h4,article .entry-content h5,article .entry-content h6,article .entry-content pre{margin-top:15px}article pre b.name{color:#eee;font-family:"Consolas","Liberation Mono",Courier,monospace;font-size:60px;line-height:1;pointer-events:none;position:absolute;right:10px;top:10px}article .entry-content .date{color:#999}article .entry-content ul ul,article .entry-content ul ol,article .entry-content ul dl,article .entry-content ol ul,article .entry-content ol ol,article .entry-content ol dl,article .entry-content dl ul,article .entry-content dl ol,article .entry-content dl dl,article .entry-content blockquote > p:first-of-type{margin-top:0}article .entry-content ul,article .entry-content ol,article .entry-content dl{margin-left:25px}.header{background-color:#fff;box-shadow:0 0 40px 0 rgba(0,0,0,0.1);box-sizing:border-box;font-size:14px;height:60px;padding:0 15px;position:absolute;width:100%}.footer{font-size:.9em;padding:15px 0 25px;text-align:center;width:auto}.header h1{font-size:30px;font-weight:400;line-height:30px;margin:15px 0px}.menu-list li a,.menu-list li span{border-bottom:solid 1px #ededed;color:#000;display:block;font-size:18px;height:60px;line-height:60px;text-align:center;width:86px}.header h1 a{color:#333}.tex .hljs-formula{background:#eee8d5}</style>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>
<header class="header">
<div class="header-title"><h1><a href="<?php echo(Typecho_Common::url("ampindex/", $this->baseurl)); ?>"><?php echo($AMPpage['publisher']);?></a></h1></div>
</header>
<article class="post"><h1 class="title"><?php echo($AMPpage['title']); ?></h1>
<div class="entry-content">
<?php echo($AMPpage['AMPtext']); ?>
</div>
<p class="notice">当前页面是本站的「<a href="//www.ampproject.org/zh_cn/">Google AMP</a>」版。查看和发表评论请点击:<a
href="<?php echo($AMPpage['permalink']); ?>">完整版 »</a></p>
<?php if(!$AMPpage['isMarkdown']){echo('<p class="notice">因本文不是用Markdown格式的编辑器书写的,转换的页面可能不符合AMP标准。</p>');} ?>
</article>
<footer><div class="footer"><p>© 2018 <a data-type="amp" href="https://github.com/holmesian/Typecho-AMP">AMP for Typecho</a> v<?php echo(AMP_Plugin::$version) ?>
, Designed by <a href="https://holmesian.org/" target="_blank">Holmesian</a>.</p></div></footer>
</body>
</html>
页面的amp模板,想修改页面amp样式的可以在此文件中修改。
MIPpage.php
<!DOCTYPE html>
<html lang="zh-cn" mip>
<head>
<meta charset="utf-8">
<meta name="X-UA-Compatible" content="IE=edge">
<title><?php echo($MIPpage['title']); ?></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<link rel="stylesheet" type="text/css" href="https://mipcache.bdstatic.com/static/v1/mip.css">
<link rel="canonical" href="<?php echo($MIPpage['permalink']); ?>">
<style mip-custom>p{text-indent: 2em;} a,abbr,acronym,address,applet,big,blockquote,body,caption,cite,code,dd,del,dfn,div,dl,dt,em,fieldset,form,h1,h2,h3,h4,h5,h6,html,iframe,img,ins,kbd,label,legend,li,object,ol,p,pre,q,s,samp,small,span,strike,strong,sub,sup,table,tbody,td,tfoot,th,thead,tr,tt,ul,var{margin:0;padding:0;border:0;font-family:inherit;font-size:100%;font-weight:inherit;font-style:inherit;vertical-align:baseline;outline:0}body{line-height:1;color:#000;background:#fff}ol,ul{list-style:none}table{vertical-align:middle;border-spacing:0;border-collapse:separate}caption,td,th{font-weight:400;text-align:left;vertical-align:middle}a img{border:none}html{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}*,:after,:before{-webkit-box-sizing:inherit;-moz-box-sizing:inherit;box-sizing:inherit}button::-moz-focus-inner,input[type=button]::-moz-focus-inner,input[type=reset]::-moz-focus-inner,input[type=submit]::-moz-focus-inner{margin:0;padding:0;border:0}button,input,select{margin:0;padding:0;border:0}body{overflow-x:hidden;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:15px;color:#444;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility}.mip-nav-wrapper{padding:0 10px;background-color:#323436}.navbar-brand{color:#fff!important}@media screen and (min-width:767px){.mip-nav-wrapper a{color:#fff!important}}@media screen and (max-width:767px){.mip-nav-wrapper .navbar-brand{margin-top:2px}}.navbar-brand{display:block;overflow:hidden;max-width:200px;line-height:41px;white-space:nowrap;text-overflow:ellipsis}mip-fixed[type=bottom],mip-fixed[type=top]{overflow:visible}.post{position:relative;padding:15px 10px;border-top:1px solid #fff;border-bottom:1px solid #ddd;word-wrap:break-word;background-color:#fff}h1.title,h2.title{padding:10px 0;font-size:28px}.post .meta{color:#666}.article-more a{color:#2479c2}.article-content .date{display:inline-block;margin:0 10px;font-size:14px;font-style:italic;color:#999}.article-content{line-height:1.6em;color:#444}@media print{.article-content{font-size:12pt}}.article-content .highlight,.article-content blockquote,.article-content dl,.article-content iframe,.article-content ol,.article-content p,.article-content table,.article-content ul{margin:1em 0}.article-content h1{font-size:2em}.article-content h2{font-size:1.5em}.article-content h3{font-size:1.3em}.article-content h1,.article-content h2,.article-content h3,.article-content h4,.article-content h5,.article-content h6{margin:1em 0;font-weight:700;line-height:1em}.article-content a{text-decoration:none;color:#0e83cd}.article-content a:hover{text-decoration:underline;color:#1094e8}@media print{.article-content a{text-decoration:underline;color:#444}.article-content a:after{content:" (" attr(href) ")";font-size:80%}}.article-content strong{font-weight:700}.article-content em{font-style:italic}.article-content dl,.article-content ol,.article-content ul{margin-left:20px}.article-content dl dl,.article-content dl ol,.article-content dl ul,.article-content ol dl,.article-content ol ol,.article-content ol ul,.article-content ul dl,.article-content ul ol,.article-content ul ul{margin-top:0;margin-bottom:0}.article-content ul{list-style:disc}.article-content ol{list-style:decimal}.article-content dl{list-style:square}.article-content li p{margin:0}.article-content li .highlight,.article-content li blockquote,.article-content li iframe,.article-content li table{margin:1em 0}.article-content img,.article-content video{max-width:100%}.article-content table{max-width:100%;border:1px solid #e3e3e3}.article-content table th{font-weight:700}.article-content table td,.article-content table th{padding:5px 15px}.article-content table tr:nth-child(2n){background:#eee}.article-content blockquote{position:relative;padding:0 20px;border:1px solid #e3e3e3;border-left:5px solid #ddd}.article-content .tip,.article-content .tip-error,.article-content .tip-info{position:relative;margin:1em 0;padding:1em 20px;border:1px solid #e3e3e3;border-left:5px solid #5fb878;border-top-right-radius:2px;border-bottom-right-radius:2px}.article-content .tip br:first-child,.article-content .tip-error br:first-child,.article-content .tip-info br:first-child{display:none}.article-content .tip-error:before,.article-content .tip-info:before{content:"!";position:absolute;top:16px;left:-12px;width:20px;height:20px;font-family:Dosis,"Source Sans Pro","Helvetica Neue",Arial,sans-serif;font-size:14px;font-weight:700;line-height:20px;text-align:center;color:#fff;border-radius:100%;background-color:#5fb878}.article-content .tip-info{border-left-color:#1e9fff}.article-content .tip-info:before{background-color:#1e9fff}.article-content .tip-error{border-left-color:#ff5722}.article-content .tip-error:before{background-color:#ff5722}.main{padding:72px 10px 0;max-width:1000px;margin:0 auto}@media screen and (max-width:767px){.main{padding-top:44px}}code,pre{font-family:"Source Code Pro",Monaco,Menlo,Consolas,monospace;font-size:.95em;color:#4d4d4c;background:#eee;overflow-x:auto;-webkit-overflow-scrolling:touch}code{padding:0 5px}pre{padding:10px 15px;line-height:22px}pre code{display:block;padding:0;border:none}.highlight{overflow:auto;margin:0;padding:10px 15px;color:#4d4d4c;background:#eee}.highlight table{margin:0!important;border:0}.highlight table td,.highlight table th{padding:0}.highlight figcaption{margin:-5px 0 5px;font-size:.9em;color:#999}.highlight figcaption:after,.highlight figcaption:before{content:"";display:table}.highlight figcaption:after{clear:both}.highlight figcaption a{float:right}.highlight pre{padding:0;border:none;background:0 0}.highlight .line{height:22px}pre .comment,pre .title{color:#8e908c}pre .attribute,pre .css .class,pre .css .id,pre .css .pseudo,pre .html .doctype,pre .regexp,pre .ruby .constant,pre .tag,pre .variable,pre .xml .doctype,pre .xml .pi,pre .xml .tag .title{color:#c82829}pre .built_in,pre .constant,pre .literal,pre .number,pre .params,pre .preprocessor{color:#f5871f}pre .class,pre .css .rules .attribute,pre .ruby .class .title{color:#718c00}pre .header,pre .inheritance,pre .ruby .symbol,pre .string,pre .value,pre .xml .cdata{color:#718c00}pre .css .hexcolor{color:#3e999f}pre .coffeescript .title,pre .function,pre .javascript .title,pre .perl .sub,pre .python .decorator,pre .python .title,pre .ruby .function .title,pre .ruby .title .keyword{color:#4271ae}pre .javascript .function,pre .keyword{color:#8959a8}.footer{line-height:1.8;text-align:center;padding:15px;border-top:1px solid #fff;font-size:.9em;color:#999}.footer a{color:#2479c2}.pagination{width:100%;line-height:20px;position:relative;border-top:1px solid #fff;border-bottom:1px solid #ddd;padding:20px 0;overflow:hidden}.pagination .prev{float:left}.pagination .next{float:right}.pagination a{color:#2479c2}</style>
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "<?php echo($MIPpage['mipurl']);?>",
"appid": "<?php echo($MIPpage['APPID']);?>",
"title": "<?php echo($MIPpage['title']); ?>",<?php if(is_array($MIPpage['imgData'])){ ?>
"images": [
"<?php echo($MIPpage['imgData']['url']); ?>"
],<?php }?>
"description": "<?php echo($MIPpage['desc']);?>",
"pubDate": "<?php echo($MIPpage['date']); ?>",
"upDate": "<?php echo($MIPpage['modified']); ?>",
"lrDate": "<?php echo($MIPpage['modified']); ?>",
"isOrignal":1
}
</script>
</head>
<body>
<mip-cambrian site-id="<?php echo($MIPpage['APPID']);?>"></mip-cambrian>
<mip-fixed type="top">
<div class="mip-nav-wrapper">
<mip-nav-slidedown data-id="bs-navbar" data-showbrand="1" data-brandname="<?php echo($MIPpage['publisher']);?>" class="mip-element-sidebar container">
<nav id="bs-navbar" class="navbar-collapse collapse navbar navbar-static-top">
<ul class="nav navbar-nav navbar-right">
<li><a data-type="mip" href="/">首页</a></li>
<li><a href="<?php echo($MIPpage['permalink']); ?>">本文PC版</a></li>
<li class="navbar-wise-close"><span id="navbar-wise-close-btn"></span></li>
</ul>
</nav>
</mip-nav-slidedown>
</div>
</mip-fixed>
<div class="main">
<div class="post-detail">
<article class="post"><h1 class="title"><?php echo($MIPpage['title']); ?></h1>
<div class="meta"><?php echo($MIPpage['date']); ?></div>
<div class="article-content">
<?php echo($MIPpage['MIPtext']); ?>
<div class="tip">当前页面是本站的「<a href="https://www.mipengine.org/">Baidu MIP</a>」版。发表评论请点击:<a
href="<?php echo($MIPpage['permalink']); ?>">完整版 »</a></div>
<?php if(!$MIPpage['isMarkdown']){echo('<div class="tip-error">因本文不是用Markdown格式的编辑器书写的,转换的页面可能不符合MIP标准。</div>');} ?>
</article>
</div>
</div>
<div class="footer"><p>© 2018 <a data-type="mip" href="https://github.com/holmesian/Typecho-AMP">MIP for Typecho</a> v<?php echo(AMP_Plugin::$version) ?>
, Designed by <a href="https://holmesian.org/" target="_blank">Holmesian</a>.</p></div>
<mip-fixed type="gototop">
<mip-gototop></mip-gototop>
</mip-fixed>
<script src="https://mipcache.bdstatic.com/static/v1/mip.js"></script>
<script src="https://mipcache.bdstatic.com/static/v1/mip-nav-slidedown/mip-nav-slidedown.js"></script>
<script src="https://mipcache.bdstatic.com/static/v1/mip-gototop/mip-gototop.js"></script>
<script src="https://mipcache.bdstatic.com/static/v1/mip-fixed/mip-fixed.js"></script>
<script src="https://mipcache.bdstatic.com/extensions/platform/v1/mip-cambrian/mip-cambrian.js"></script>
<?php
if(isset($MIPpage['mip_stats_token'])){
?>
<script src="https://c.mipcdn.com/static/v1/mip-stats-baidu/mip-stats-baidu.js"></script>
<mip-stats-baidu>
<script type="application/json">
{
"token": "<?php echo($MIPpage['mip_stats_token']); ?>",
"_setCustomVar": [1, "login", "1", 2],
"_setAutoPageview": [true]
}
</script>
</mip-stats-baidu>
<?php
}
?>
</body>
</html>
页面的mip模板,想修改mip样式的可以在此文件中修改。
注意:mip是百度提供针对移动端轻量化网页的解决方案,百度同时也支持amp标准。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
感谢分享。