勉强从灾难中恢复

作者:V君 发布于:2023-5-3 20:49 Wednesday 分类:小服杂记

数据库和备份的树莓派双双失效,找到一份年初的备份,还好这半年没写博客

评论(2) 引用(0) 浏览(308)

总算是修好邮件通知功能了

作者:V君 发布于:2022-5-28 19:15 Saturday 分类:小服杂记

这次排查过程我只能用下面的两张梗图来形容。

首先不知道如何断点调试运行在 Apache 的 PHP,那就只能找到输出日志的方法,然后拼命打log。(第一张梗图)

其次打了 log 得到的错误信息莫名其妙,可能是发邮件的库和自己搭的邮件服务器存在兼容问题,调着调着莫名其妙又通了,然后去掉打 log 的代码,做出思考状。(第二张梗图)

点击查看原图

点击查看原图

评论(0) 引用(0) 浏览(204)

引入ace编辑器用作代码高亮(杀鸡焉用牛刀?

作者:V君 发布于:2020-3-20 22:57 Friday 分类:小服杂记

博客中有不少文章把代码段贴出来,有(dan)空(teng)的时候想办法去弄点样式,没(lan)空的时候就直接贴纯文本。是时候应该解决一下了。那就去看看用什么组件好吧。

(放狗出去找)发现了 highlight.js ,看起来不错,但不支持显示行号,并且作者也不打算实现它。那就再找找吧,(找了一会儿),想起 ace 编辑器了,如果只要设置成只读,它就是一个优秀的代码高亮组件,还能折叠代码块。

废话少说开始干!首先找到代码插入点,这次我选择在 content/templates/default/footer.php 底部的 #wrap 结束标记后面,插入 CDN 库引用然后写了下面的代码来启用。

先TL;DR一下使用方法:在需要高亮的元素上增加以下属性

  1. highlight="ace" 启用代码高亮
  2. ace-lang="javascript" 必选,指定代码语言
  3. ace-theme="chrome" 可选,配色主题

代码语言和配色主题可以参照源代码文件名。

注释掉 log 语句并甩锅给 IE(

//replace nbsp \xa0 to normal space \x20
function normalizeSpaces(elm){
    var nodes = elm.childNodes;
    for (var i=0; i < nodes.length; ++i){
        if(nodes[i].nodeName === "#text") nodes[i].textContent = nodes[i].textContent.split("\xa0").join('\x20');
        else normalizeSpaces(nodes[i]);
    }
}

if (ace===undefined){
    console.log('highlight: ace undefined, no works');
}else{
    var items = document.querySelectorAll('[highlight=ace]');
    //console.log(`highlight: found ${items.length} element(s) to highlight, dealing with it.`);
    for (var i=0;i<items.length;++i){
        var item = items[i];
        
        var aceLang=item.getAttribute("ace-lang");
        if (aceLang === null){
            //console.warn(`highlight: the highlight element #${i} missing attribute 'ace-lang', skipped`);
            continue;
        }
        
        normalizeSpaces(item);
        
        var aceTheme=item.getAttribute("ace-theme");
        if (aceTheme === null) aceTheme = "Chrome";
        
        var editor = ace.edit(item);
        editor.setReadOnly(true);
        editor.setOptions({maxLines: Infinity});
        editor.setTheme("ace/theme/"+aceTheme);
        editor.session.setMode("ace/mode/"+aceLang);
        editor.setValue( editor.getValue().split('\n').join('\r\n'));
        editor.getSession().selection.clearSelection();
    }
}

继续水

标签: 软件开发 javascript Web技术

评论(0) 引用(0) 浏览(866)

将全部公开的SVN项目迁移到Git了

作者:V君 发布于:2020-3-19 20:12 Thursday 分类:小服杂记

由于 SVN 的占用空间日益增大,目前又主要以 Git 为主,使得备份空间占用变得越来越没有意义,因此花了几天时间来搬运。在这里向大家分担一下这个过程。其实也不复杂,只是比较繁琐。因为找不到好用的迁移方法,我用的是最笨的手动方式,即从 SVN 导出最新版然后推送到 Git。

找到办法之后就可以制定行动方案了,因为博客上面许多文章都引用了 SVN 的链接,得找出它们,将引用的项目搬到 Git,然后更新链接。大概被分成了如下 3 个阶段:

  1. 直接从数据库中搜索带有 SVN 链接文章
  2. 导出最新版,创建 Git 仓库,导入并检查编译
  3. 推送,然后重新回到步骤 1 直到所有文章都处理完

最后把 SVN 的公开访问关闭了,如果有需要访问原 SVN 有、但没被文章引用的项目,请留言,我会考虑为其创建公开的 Git 仓库。

标签: 源码管理

评论(2) 引用(0) 浏览(544)

在 IIS 使用 web.config 配置域名端口跳转

作者:V君 发布于:2020-2-9 0:21 Sunday 分类:小服杂记

— TL;DR —

按需将以下配置节点添加到 web.config ,修改目标域名,完成。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
 <security>
   <requestFiltering>
   <fileExtensions allowUnlisted="true">
    <remove fileExtension=".cs" />
   </fileExtensions>
  </requestFiltering>
 </security>
 <rewrite>
  <rules>
    <rule name="RedirectGogs" stopProcessing="true" enabled="true">
      <match url="^gogs/(.*$)" />
      <action type="Redirect" redirectType="Temporary" url="https://gogs.topcl.net:8443/{R:1}"/>
    </rule>

    <rule name="RedirectExaWww" stopProcessing="true" enabled="true">
      <match url="^(?![\._].*$).*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="www\.example\.com" />
      </conditions>
      <action type="Redirect" redirectType="Temporary" url="https://blog.example.com:8443/{R:0}"/>
    </rule>
    <rule name="RedirectExa" stopProcessing="true" enabled="true">
      <match url="^(?![\._].*$).*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="example\.com" />
      </conditions>
      <action type="Redirect" redirectType="Temporary" url="https://blog.example.com:8443/{R:0}"/>
    </rule>

    <rule name="DefultRedirectBlog" stopProcessing="true" enabled="true">
      <match url="^(?![\._].*$).*" />
      <action type="Redirect" redirectType="Temporary" url="https://blog.topcl.net:8443/{R:0}"/>
    </rule>
  </rules>
 </rewrite>
</system.webServer>
</configuration>

— 听我扯扯 —

咋一看,不就是 rewrite + redirect (307) 不就好? 其实没有那么简单,比如源代码连接里以 .cs 后缀的代码文件 ()就在跳转的时候被 IIS 拦下来 404 了,因此还得额外加白。你可能会担心安全风险,但我这个空间仅仅用来跳转,根目录下只有这个 web.config 文件。

二月份的文章也只能这么水了,因为疫情只能把自己关在家

— 更新 —

将正则表达式改为 ^(?![\._].*$).* 可以忽略以指定字符开头的路径,方便申请 Let's 证书和临时放些文件,使配置更灵活

— 更新Ⅱ —

使用 conditions 实现别名支持,使空间变跳转 hub,将其利用价值榨干

标签: SSL证书 HTTPS ASP.NET IIS

评论(0) 引用(0) 浏览(966)

Powered by emlog 去你妹的备案 sitemap