├── assets ├── main.css ├── main.js └── normalize.css ├── .gitignore ├── .gitattributes ├── includes ├── header.php ├── footer.php └── head.php ├── 404.php ├── page.php ├── post.php ├── archive.php ├── index.php ├── README.md ├── LICENSE ├── functions.php └── libs ├── Contents.php └── Utils.php /assets/main.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /assets/main.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | temp/* 3 | .DS_Store 4 | package-lock.json -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=PHP 2 | *.css linguist-language=PHP 3 | *.html linguist-language=PHP -------------------------------------------------------------------------------- /includes/header.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /404.php: -------------------------------------------------------------------------------- 1 | need('includes/head.php'); 11 | $this->need('includes/header.php'); 12 | ?> 13 | 14 | 15 | 16 | need('includes/footer.php'); ?> -------------------------------------------------------------------------------- /page.php: -------------------------------------------------------------------------------- 1 | need('includes/head.php'); 11 | $this->need('includes/header.php'); 12 | ?> 13 | 14 | 15 | 16 | need('includes/footer.php'); ?> -------------------------------------------------------------------------------- /post.php: -------------------------------------------------------------------------------- 1 | need('includes/head.php'); 11 | $this->need('includes/header.php'); 12 | ?> 13 | 14 | 15 | 16 | need('includes/footer.php'); ?> -------------------------------------------------------------------------------- /archive.php: -------------------------------------------------------------------------------- 1 | need('includes/head.php'); 11 | $this->need('includes/header.php'); 12 | ?> 13 | 14 | 15 | 16 | need('includes/footer.php'); ?> -------------------------------------------------------------------------------- /includes/footer.php: -------------------------------------------------------------------------------- 1 | 标签,并关闭
、 标签 6 | * 7 | * @author 熊猫小A 8 | */ 9 | if (!defined('__TYPECHO_ROOT_DIR__')) exit; 10 | ?> 11 | 12 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 熊猫小A 6 | * 7 | * @package Typecho-Theme-X 8 | * @author 熊猫小A 9 | * @version 1.0 10 | * @link https://blog.imalan.cn 11 | */ 12 | if (!defined('__TYPECHO_ROOT_DIR__')) exit; 13 | $this->need('includes/head.php'); 14 | $this->need('includes/header.php'); 15 | ?> 16 | 17 | 18 | 19 | need('includes/footer.php'); ?> -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 一个 Typecho 主题开发起步框架 2 | 3 | 我在为 Typecho 写主题时发现了几个问题: 4 | 5 | - 某些代码可以复用,没必要每次都写一遍 6 | - Typecho 文档不充分,某些方法每次用到都要现查 7 | - 某些方法 Typecho 的接口太复杂或者压根就没有实现 8 | - 某些方法在不同的 Typecho 版本行为不一致 9 | - 我的主题都有比较相似的目录结构 10 | 11 | 因此我准备把自己的最佳实践打包一下,美其名曰一个「框架」,其实只是为了减少一些无谓的工作量。 12 | 13 | ~~是不是闻到了 JQuery 的味道~~ 14 | 15 | 使用时,直接下载本框架,并在其中删改、添加代码。Utils.php 与 Contents.php 中提供了一些常用的代码,可以看看。 16 | 17 | **非常欢迎各种 pull request** 18 | 19 | 目录结构: 20 | 21 | ``` 22 | index.php 23 | post.php 24 | page.php 25 | archive.php 26 | 404.php 27 | functions.php 28 | includes 29 | |-- head.php 30 | |-- header.php 31 | |-- footer.php 32 | libs 33 | |-- Utils.php 34 | |-- Contents.php 35 | assets 36 | |-- main.css 37 | |-- main.js 38 | ``` 39 | 40 | 41 | ## License 42 | 43 | MIT © [AlanDecode](https://github.com/AlanDecode) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 AlanDecode 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /assets/normalize.css: -------------------------------------------------------------------------------- 1 | html{line-height:1.15;-webkit-text-size-adjust:100%;}body{margin:0;}main{display:block;}h1{font-size:2em;margin:0.67em 0;}hr{box-sizing:content-box;height:0;overflow:visible;}pre{font-family:monospace,monospace;font-size:1em;}a{background-color:transparent;}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted;}b,strong{font-weight:bolder;}code,kbd,samp{font-family:monospace,monospace;font-size:1em;}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sub{bottom:-0.25em;}sup{top:-0.5em;}img{border-style:none;}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0;}button,input{overflow:visible;}button,select{text-transform:none;}button,[type="button"],[type="reset"],[type="submit"]{-webkit-appearance:button;}button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0;}button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted ButtonText;}fieldset{padding:0.35em 0.75em 0.625em;}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal;}progress{vertical-align:baseline;}textarea{overflow:auto;}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0;}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto;}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px;}[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}details{display:block;}summary{display:list-item;}template{display:none;}[hidden]{display:none;} -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | 11 | 12 | contentEx = array('Contents','parseContent'); 23 | Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('Contents','parseContent'); 24 | 25 | /** 26 | * 主题启用时执行的方法 27 | */ 28 | function themeInit() { 29 | /** 30 | * 重置某些设置项,采用数据库查询方式完成 31 | */ 32 | $db = Typecho_Db::get(); 33 | 34 | /* 关闭评论反垃圾保护,使用 PJAX 时可能需要取消注释以下 4 行 */ 35 | // $query = $db->update('table.options')->rows(array('value'=>'0'))->where('name=?', 'commentsAntiSpam'); 36 | // $db->query($query); 37 | // $query = $db->update('table.options')->rows(array('value'=>'0'))->where('name=?', 'commentsCheckReferer'); 38 | // $db->query($query); 39 | 40 | /* 设置评论最大嵌套层数 */ 41 | $query = $db->update('table.options')->rows(array('value'=>'999'))->where('name=?', 'commentsMaxNestingLevels'); 42 | $db->query($query); 43 | 44 | /* 强制新评论在前 */ 45 | $query = $db->update('table.options')->rows(array('value'=>'DESC'))->where('name=?', 'commentsOrder'); 46 | $db->query($query); 47 | 48 | /* 默认显示第一页评论 */ 49 | $query = $db->update('table.options')->rows(array('value'=>'first'))->where('name=?', 'commentsPageDisplay'); 50 | $db->query($query); 51 | } 52 | 53 | /** 54 | * 主题后台设置 55 | */ 56 | function themeConfig($form) { 57 | 58 | } 59 | 60 | /** 61 | * 文章与独立页自定义字段 62 | */ 63 | function themeFields(Typecho_Widget_Helper_Layout $layout) { 64 | 65 | } -------------------------------------------------------------------------------- /includes/head.php: -------------------------------------------------------------------------------- 1 | 标签,并开始 、 标签 6 | * 7 | * @author 熊猫小A 8 | */ 9 | if (!defined('__TYPECHO_ROOT_DIR__')) exit; 10 | ?> 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | is('post') || $this->is('page')){ 24 | if(isset($this->fields->banner)) 25 | $banner=$this->fields->banner; 26 | if(isset($this->fields->excerpt)) 27 | $description = $this->fields->excerpt; 28 | }else{ 29 | $description = Helper::options()->description; 30 | } 31 | ?> 32 |