What & How & Why

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
other:website:misc [2022/06/24 11:46] codinghareother:website:misc [2024/02/04 16:17] (当前版本) – [Disqus loading on scroll] codinghare
行 22: 行 22:
 cd /etc/ cd /etc/
 rm my.inf rm my.inf
 +</code>
 +==PID file not found==
 +<code bash>
 +#error msg
 +ERROR! MySQL server PID file could not be found!
 +</code>
 +这种情况多半是硬盘空间满了导致系统强制结束了 mysql 的进程。用下面的命令之后再重启一下 mysql 进系统看看。
 +<code bash>
 +rm -f /tmp/mysql-5.6.sock tmp/mysql-5.6.sock.lock
 </code> </code>
  
行 86: 行 95:
 } }
 </code> </code>
 +===所有 MIMe 类型=== 
 +[[https://gist.github.com/AlekseiCherkes/690551fafa3a939c54ed|Link]]
 ===Dokuwiki 使用=== ===Dokuwiki 使用===
  
行 108: 行 118:
 always_populate_raw_post_data = -1 always_populate_raw_post_data = -1
 </code> </code>
 +==Igor 版本 svg 缩放不正确==
 +<WRAP center round important 100%>
 +官方 issue 中解释该设置是一个 guard,不应修改。推荐对指定插件进行修改。
 +</WRAP>
 +将 ''/lib/styles/all.css'' 中 ''svg''
 +<code css>
 +width: 1.2em;
 +</code>
 +替换为
 +<code css>
 +width: auto;
 +</code>
 +
 ====服务器通用前端优化==== ====服务器通用前端优化====
  
行 116: 行 139:
 <del>**解决方法(过时)**:由于 AMH 的 ''Nginx.conf'' 自带 caching,需要手动去 ''/yourwebdir/vhost/yourweb.conf'' 将如下的缓存规则删除。</del> <del>**解决方法(过时)**:由于 AMH 的 ''Nginx.conf'' 自带 caching,需要手动去 ''/yourwebdir/vhost/yourweb.conf'' 将如下的缓存规则删除。</del>
  
-<WRAP  round tip 60%>+<WRAP  round tip100%>
 解决方法:使用新版本的重写规则,请参见前面。 解决方法:使用新版本的重写规则,请参见前面。
 </WRAP> </WRAP>
行 225: 行 248:
 <?php echo timesince($comments->created);?> <?php echo timesince($comments->created);?>
 </code> </code>
-==评论:回复评论自带@跳径,但 AMH 对此似乎并不友好。另外一种办法是通过面板建立**子域主机**来重新定向域名的根目录到 ''public''。举个例子,如果需要指定域名 domain.com 到该目录,需要修改的如下:+==评论:回复评论自带@跳转== 
 +首先到 ''function.php'' 中添加如下两个函数: 
 +<code php> 
 +//获取评论的锚点链接 
 +function get_comment_at($coid) 
 +
 +    $db   = Typecho_Db::get(); 
 +    $prow = $db->fetchRow($db->select('parent')->from('table.comments'
 +                                 ->where('coid = ? AND status = ?', $coid, 'approved')); 
 +    $parent = $prow['parent']; 
 +    if ($parent != "0") { 
 +        $arow = $db->fetchRow($db->select('author')->from('table.comments'
 +                                     ->where('coid = ? AND status = ?', $parent, 'approved')); 
 +        $author = $arow['author']; 
 +        $href   = '<a href="#comment-' . $parent . '">@' . $author . '</a>'; 
 +        echo $href; 
 +    } else { 
 +        echo ''; 
 +    } 
 +
 +//输出评论内容 
 +function get_filtered_comment($coid){ 
 +    $db   = Typecho_Db::get(); 
 +    $rs=$db->fetchRow($db->select('text')->from('table.comments'
 +                                 ->where('coid = ? AND status = ?', $coid, 'approved')); 
 +    $content=$rs['text']; 
 +    echo $content; 
 +
 +?> 
 +</code> 
 +\\ 
 +再到 ''comments.php'' 中使用如下代码调用即可: 
 +<code linenums:1> 
 +<?php get_comment_at($comments->coid)?> 
 +</code> 
 +==添加自定义html标签到文章内容== 
 +找到文件夹 ''/var'' 下的文件 ''HyperDown.php'' 第十七行,添加需要使用的标签即可。 
 +===Typecho 升级指南=== 
 + 
 +//Typecho// 可以通过以下方式来进行升级: 
 + 
 +  - 下载最新的版本:[[https://github.com/typecho/typecho|Typecho On Github]] 
 +  - 删除服务器上三个目录的文件,如果修改了源代码可以使用 //Github// 的对比工具来进行合并。三个目录分别是:''/admin'', ''/var'', 和根目录下的 ''index.php''。 
 +  - 上传最新的对应文件即可。 
 + 
 +===Typecho URL重写=== 
 + 
 +==Apache 重写规则== 
 +添加如下代码到 ''.htaccess'' 文件中即可。注意:''RewriteBase'' 后是网站的目录。 
 +<code apache> 
 +<IfModule mod_rewrite.c > 
 +    RewriteEngine On 
 +    RewriteBase / 
 +    RewriteCond %{REQUEST_FILENAME} !-f 
 +    RewriteCond %{REQUEST_FILENAME} !-d 
 +    RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] 
 +</IfModule> 
 +</code> 
 + 
 +===InstantClick=== 
 + 
 +''instantclick.js'' 是一种ajax无刷新和预加载页面的技术,对于普通博客程序,有着明显的加速作用。''instantclick.js'' ≈ ''pjax'' 加上预加载页面,而且,使用方法也十分的简单。 
 + 
 +==安装InstantClick== 
 + 
 +下载 [[http://instantclick.io/download|InstantClick]] 
 +\\ 
 +\\ 
 +在 ''footer.php'' 的 ''</body>'' 标签之前插入以下代码: 
 +<code js> 
 +... 
 +<script src="instantclick.min.js" data-no-instant></script> 
 +<script data-no-instant>InstantClick.init();</script> 
 +</body> 
 +</html> 
 +</code> 
 + 
 +==点击时候的预加载== 
 + 
 +默认情况下是在鼠标悬停到链接上方即开始加载,有时候这样会带来服务器的额外开销问题。将 ''init'' 函数的参数设置为 ''mousedown'' 则可以通过点击的一瞬间进行预加载: 
 +<code> 
 +InstantClick.init('mousedown'); 
 +</code> 
 + 
 +==修改预加载条的颜色== 
 + 
 +在样式表中加入如下代码即可: 
 +<code css> 
 +#instantclick-bar { background: gray; } 
 +</code> 
 + 
 +==与 PrismJS兼容== 
 + 
 +先对 ''Prismjs'' 中需要预加载的部分进行设置: 
 +\\ 
 +\\ 
 +打开 ''Plugin.php'' 文件,找到 ''58'' 行: 
 +<code html js> 
 +<script>var pres = document.getElementsByTagName('pre'); 
 +</code> 
 +改为: 
 +<code html> 
 +<script data-no-instant>var pres = document.getElementsByTagName('pre'); 
 +</code> 
 +找到 ''64'' 行: 
 +<code html> 
 +<script src="' . $jsUrl . '"></script> 
 +</code> 
 +改为: 
 +<code html> 
 +<script src="' . $jsUrl . '" data-no-instant></script> 
 +</code> 
 +找到 ''66'' 行: 
 +<code html> 
 +<script defer="defer" src="' . Helper::options()->pluginUrl . '/Prismjs/line-number-wrap-fix.js' . '"></script> 
 +</code> 
 +改为: 
 +<code html js> 
 +<script defer="defer" src="' . Helper::options()->pluginUrl . '/Prismjs/line-number-wrap-fix.js' . '" data-no-instant></script> 
 +</code> 
 +\\ 
 +再修改位于 ''footer.php'' 中 ''instantclick'' 的白名单部分,添加属于 ''prismjs'' 的规则: 
 +<code js> 
 +if (typeof Prism !== 'undefined') {<?php  if (Helper::options()->plugin('Prismjs')->showln): ?> 
 +var pres = document.getElementsByTagName('pre'); 
 +    for (var i = 0; i < pres.length; i++){ 
 +        if (pres[i].getElementsByTagName('code').length > 0) 
 +            pres[i].className  = 'line-numbers';} <?php endif; ?> 
 +Prism.highlightAll(true,null);
 +</code> 
 +PHP 部分: 
 +<code php> 
 +{<?php  if (Helper::options()->plugin('Prismjs')->showln): ?>''  
 +</code> 
 +对判断插件是否使用了行号。如果没启用插件,会导致网站 **505** 错误。 
 +\\ 
 +\\ 
 +如果不使用行号,直接使用以下代码: 
 +<code php> 
 + if (typeof Prism !== 'undefined') { Prism.highlightAll(true,null);
 +</code> 
 + 
 +===Mathjax=== 
 +==mathjax 3 简单配置== 
 +<code js> 
 +MathJax = { 
 +        showProcessingMessages: false, 
 +        messageStyle: "none",     
 +    tex: { 
 +        inlineMath: [ ["$","$"], ["\\\\(","\\\\)"] ], 
 +        displayMath: [ ["$$","$$"], ["\\\\[","\\\\]"] ], 
 +        processEscapes: true 
 +    }, 
 +    svg: { 
 +        fontCache: "global" 
 +    } 
 +
 +</code> 
 +==igor 版本的缩放问题== 
 +添加以下代码到 ''/lib/styles/all.css'': 
 +<code cpp> 
 +mjx-container[jax="SVG"] > svg { 
 +    height: auto; 
 +    width: auto; 
 +
 +</code> 
 +==Mathjax与InstantClick不兼容== 
 + 
 +在 ''footer.php'' 中找到 ''InstantClick.on('change', function(isInitialLoad)'' 部分,加入以下规则: 
 +<code> 
 +if (typeof MathJax !== 'undefined'){MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
 +</code> 
 +==Mathjax的直接添加== 
 + 
 +在 ''header.php'' 中的 ''<head>'' 之间加入如下代码: 
 +<code html> 
 +<script type="text/x-mathjax-config"> 
 +  MathJax.Hub.Config({ 
 +    extensions: ["tex2jax.js"], 
 +    jax: ["input/TeX", "output/HTML-CSS"], 
 +    tex2jax: { 
 +      inlineMath: [ ['$','$'], ["\\(","\\)"] ], 
 +      displayMath: [ ['$$','$$'], ["\\[","\\]"] ], 
 +      processEscapes: true 
 +    }, 
 +     
 +    "HTML-CSS": { availableFonts: ["TeX"] } 
 +  }); 
 +</script> 
 +<script type="text/javascript" 
 +   src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> 
 +</script> 
 +</code> 
 +<WRAP center round info 100%> 
 +近日 //MathJax// 自营 CDN 已经停止服务,需自行寻找相关 CDN。 
 +</WRAP> 
 +\\ 
 +==Mathjax按需加载== 
 +首先在 ''post.php'' 中添加一个全局变量用于检测页面是否有数学公式: 
 +<code php> 
 +<?php $GLOBALS['mathjax'] = strpos($this->content, '[') || strpos($this->content, '('); ?> 
 +</code> 
 +接着到 Mathjax.js 调用的地方设置条件(我的是''footer.php''): 
 +<code php> 
 +<?php if($GLOBALS['mathjax']):?> 
 +  <!--mathjax--> 
 +  <script type="text/javascript" src="https://cdn.staticfile.org/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script> 
 +<?php endif;?> 
 +</code> 
 + 
 +==Mathjax不显示加载信息== 
 +在 ''MathJax.Hub.Config'' 中添加如下代码: 
 +<code js> 
 +showProcessingMessages: false, //关闭js加载过程信息 
 +messageStyle: "none", //不显示信息 
 +</code> 
 + 
 +===Disqus=== 
 + 
 +==Disqus loading on scroll== 
 + 
 +<del>本实现需要 ''jquery'' 支持,并编辑  ''comments.php''。</del> 
 +\\ 
 +<WRAP round tip 60%> 
 +新版本不再使用 jquery。 
 +</WRAP> 
 + 
 +\\ 
 +\\ 
 +在 ''comments.php'' 中加入 如下 JS 代码: 
 +<code js> 
 +<script> 
 +var disqus_loaded = false; 
 + 
 +function load_disqus() 
 +
 +  disqus_loaded = true; 
 +  var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; 
 +  dsq.src = "https://codinghare.disqus.com/embed.js"; 
 +  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); 
 +
 + 
 +window.onscroll = function(e) { 
 +    if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { 
 +        //hit bottom of page 
 +        if (disqus_loaded==false){ load_disqus() }; 
 +    } 
 +}; 
 +</script> 
 +</code> 
 +\\ 
 +注意替换 ''embed.js'' 的地址为自己的 Disqus地址(直接替换 shortname 即可)。 
 +\\ 
 +\\ 
 +html 调用: 
 +<code html> 
 +<div id="disqus_thread"></div> 
 +</code> 
 + 
 +====Flarum==== 
 +===解决 nginx 重写的问题=== 
 +Flarum 自己带一个子目录 ''public'' 作为论坛的首页目录。很多网上的教程建议直接重写 vhost 中的 root 路径,但 AMH 对此似乎并不友好。另外一种办法是通过面板建立**子域主机**来重新定向域名的根目录到 ''public''。举个例子,如果需要指定域名 domain.com 到该目录,需要修改的如下:
   -  绑定 ''127.0.0.1'' 到**父主机**   -  绑定 ''127.0.0.1'' 到**父主机**
   - 绑定 domain.com 到子域主机   - 绑定 domain.com 到子域主机