Browse Source

change js and css version to it's mtime

master
filesite 3 years ago
parent
commit
c42b529e1b
  1. 31
      plugins/Html.php
  2. 10
      themes/googleimage/views/layout/main.php

31
plugins/Html.php

@ -0,0 +1,31 @@
<?php
/**
* 常用的处理HTML的方法
*/
Class Html {
//获取js、css文件的修改时间作版本号
public static function getStaticFileVersion($filename, $type = 'css') {
$ver = 0;
$filepath = '';
switch ($type) {
case 'css':
$filepath = __DIR__ . '/../www/css/' . $filename;
break;
default:
$filepath = __DIR__ . '/../www/js/' . $filename;
break;
}
if (!empty($filepath) && file_exists($filepath)) {
$fp = fopen($filepath, 'r');
$fstat = fstat($fp);
fclose($fp);
$ver = $fstat['mtime'];
}
return $ver;
}
}

10
themes/googleimage/views/layout/main.php

@ -1,4 +1,8 @@
<!DocType html> <?php
//常用方法
require_once __DIR__ . '/../../../../plugins/Html.php';
?><!DocType html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@ -9,7 +13,7 @@
<!--for theme googleimage--> <!--for theme googleimage-->
<link href="/css/blueimp-gallery.min.css" rel="stylesheet"> <link href="/css/blueimp-gallery.min.css" rel="stylesheet">
<link href="/css/github-markdown-dark.css" rel="stylesheet"> <link href="/css/github-markdown-dark.css" rel="stylesheet">
<link href="/css/googleimage.css?v<?=time()?>" rel="stylesheet"> <link href="/css/googleimage.css?v<?=Html::getStaticFileVersion('googleimage.css', 'css')?>" rel="stylesheet">
<style> <style>
<?php if (!empty(FSC::$app['config']['googleimage']['imageHeight'])) { ?> <?php if (!empty(FSC::$app['config']['googleimage']['imageHeight'])) { ?>
.img-item img{height: <?php echo FSC::$app['config']['googleimage']['imageHeight']; ?>px;} .img-item img{height: <?php echo FSC::$app['config']['googleimage']['imageHeight']; ?>px;}
@ -93,6 +97,6 @@ eof;
<script src="/js/main.js?v.1.0"></script> <script src="/js/main.js?v.1.0"></script>
<!--for theme googleimage--> <!--for theme googleimage-->
<script src="/js/blueimp-gallery.min.js"></script> <script src="/js/blueimp-gallery.min.js"></script>
<script src="/js/googleimage.js?v<?=time()?>"></script> <script src="/js/googleimage.js?v<?=Html::getStaticFileVersion('googleimage.js', 'js')?>"></script>
</body> </body>
</html> </html>

Loading…
Cancel
Save