标签 typecho 下的文章
标签 typecho 下的文章
百度官方推荐的UEditor for Typecho第三方插件,支持Typecho 1.0/0.9/0.8。
1、下载和安装
注:Typecho 1.0/0.9用户请在[控制台/个人设置]中关闭Markdown解析再启用插件!
1)直接下载zip压缩包: 点这里 。
2)解压后,将 UEditor 文件夹放入 /typecho/usr/plugins/ 下,然后到Typecho后台启用插件即可。
2、修改主题文件
为了在页面展示中显示语法高亮,还需要修改一下主题文件,在 footer.php 中加入如下代码:
<!--加入高亮的js和css文件,如果你的编辑器和展示也是一个页面那么高亮的js可以不加载--> <script type="text/javascript" src="<?php $this->options->siteUrl(); ?>usr/plugins/UEditor/ueditor/third-party/SyntaxHighlighter/shCore.js"></script> <link rel="stylesheet" type="text/css" href="<?php $this->options->siteUrl(); ?>usr/plugins/UEditor/ueditor/third-party/SyntaxHighlighter/shCoreDefault.css"/> <script type="text/javascript"> //为了在编辑器之外能展示高亮代码 SyntaxHighlighter.highlight(); // UE.getEditor('myEditor'); </script>
3、修复不会自动换行的问题
如果你的内容展示区域不够宽的话,那么代码如果超过显示区域的宽度后,仍然会继续延伸,造成页面不美观。
可以修改 shCoreDefault.css 来加入强制换行的属性:
vi /typecho/usr/plugins/UEditor/ueditor/third-party/SyntaxHighlighter/shCoreDefault.css
找到如下这一段代码,增加一句 word-break:break-all;
.syntaxhighlighter { width:100%!important; margin:.3em 0 .3em 0!important; position:relative!important; overflow:auto!important; background-color:#f5f5f5!important; border:1px solid #ccc!important; border-radius:4px!important; border-collapse:separate!important; word-break:break-all //增加这一句 }
备注:当修复了自动换行的问题后,另一个问题也随之而来。
因为一行代码显示成两行了,而左侧的行号并未因此而做出改变,这样就会造成高度不统一而错位了。
实际上UEditor 集成的 SyntaxHighlighter 版本较低,是1.5版本的,其官网都已经是3.0.83版本了。 如果插件作者能帮忙更新下就好了!
在WordPress中,固定链接可以采用Rewrite(伪静态),默认使用动态链接。在Typecho中,同样的设置叫做“永久链接”,然而Typecho默认使用了Pathinfo(也就是 http://域名/index.php/文章地址)的链接方式。如果服务器不支持Pathinfo则Typecho可以浏览首页却无法查看文章或者进入后台。如果开启了Typecho的Rewrite,则Typecho的管理后台默认支持自定义伪静态。如图:
nginx官方早就推荐使用 try_files 来替代 rewrite 了,贴一个新的推荐设置方法(with cgi.fix_pathinfo=0):
location / { # one line for typecho staticize and with cgi.fix_pathinfo=0 in php.ini more secure try_files $uri $uri/ @typecho; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { #try_files $uri @typecho; fastcgi_pass 127.0.0.1:9000; #include from snippets/fastcgi-php.conf: # regex to split $uri to $fastcgi_script_name and $fastcgi_path fastcgi_split_path_info ^(.+\.php)(/.+)$; # Check that the PHP script exists before passing it try_files $fastcgi_script_name =404; # Bypass the fact that try_files resets $fastcgi_path_info # see: http://trac.nginx.org/nginx/ticket/321 set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; fastcgi_index index.php; include fastcgi.conf; } location @typecho { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root/index.php; include fastcgi_params; }
---- 旧文:-----------------------------------------
运行环境:nginx/1.6.0 + PHP/5.4.31
location / { #rewrite rule for typecho staticize if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; } } location ~ ^.+\.php { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //也可以,但不推荐 include fastcgi_params; }
为了避免PHP CGI 中 fix_pathinfo 引起的安全隐患,现在一般关闭上述php.ini选项。此时nginx的配置:
location / { #rewrite rule for typecho staticize if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; } } location ~ ^.+\.php { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
参考资料:
Google已经完成Google Analytics到Universal Analytics的升级了,今天将本站的Google分析也升级到UA了。
资源链接:
Typecho插件:Google Analytics
Typecho插件:Universal Analytics