Hello 2022, Hello my txt blog

之前在 v2ex 上看到对于 txt blog 讨论的帖子,想到自己折腾了这么久,心也累。即使是纯前端生成的各种静态博客,也疲倦了,样式什么的,都不在意了。是时候回归原始了。

这一次很简单,创建了一个新的 blog 目录,目录结构如下:

blog/
    bin/
        md2html # markdown => html 的转换工具
    src/
        2022/
            05/
                23/
                    my-blog.md
    public
        2022/
            05/
                23/
                    my-blog.html 
        img/
        js/
        css/ 

PhpStorm 打开这个目录,配置好 sftp 路径,直接 public 映射到远程服务器的 /var/www/html/blog/ 目录。

本地编辑完 markdown 文件,用 md2html 工具生成好 html 之后自动上传完事。

额外

  • 引入 highlight.js 用来高亮代码。

  • 引入 valine.js 以支持评论。

(2023-04-15 更新)

现在再一次折腾,博客换为 Hexo 搭建,之前写的这个txt用了1年多的时间,挺有意义的,全部内容移到 https://feiffy.cc/blog202205/ 做长期保留。

之前写的极简单的 md2html.php 脚本内容如下:

<?php

$dir_files = [
     ['', 'index'],
//     ['', 'readme'],
// 注释是为了减少重复的、无意义的生成
// --- 折腾篇
//     ['2019-05-04','remove-xdebug-output-limit'],
//     ['2018/12/27', 'phpstorm-cant-highlight-smarty-template-file'],
//     ['2018/12/16', 'xampp-mysql-conf-not-work'],
//     ['2018/10/29', 'arch-linux-add-china-mirrors'],
//     ['2018/09/29', 'composer-add-laravel-china-mirrors'],
//     ['2018/07/20', 'install-xdebug'],
//     ['2018/07/18', 'auto-deploy-with-capistrano-2'],
//     ['2018/07/03', 'auto-deploy-with-capistrano'],
//     ['2018/06/25', 'ubuntu-sogou-can-not-input-chinese'],
//     ['2018/05/26', 'phpstorm-exception-breakpoint-not-work'],
//     ['2018/04/22', 'linux-tar-tutorial-in-10-minutes'],
//     ['2016/12/09', 'install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp'],
//     ['2016/11/16', 'phpmyadmin-not-found'],

// --- 技术篇
//     ['2022/07/03', 'learn-golang-1'],
//     ['2022/06/29', 'php-return-and-finally'],
//     ['2022/05/24', 'query-error-duplicate-entry-for-key'],
//     ['2022/05/23', 'hello-2022-hello-my-txt-blog'],
//     ['2022/03/30', 'codeignitor3-db-class'],
//     ['2021/11/21', 'php-session-and-cookie'],
//     ['2021/11/16', 'unit-testing-with-phpunit'],
//     ['2021/09/18', 'some-ideas-about-roam-like-app-2'],
//     ['2021/03/19', 'some-ideas-about-roam-like-app'],
//     ['2020/11/13', 'tou-tiao-i6894410680401658379'],
//     ['2020/11/03', 'codeignitor-cache-drivers-class-tutorial'],
//     ['2020/07/03', 'zhi-hu-dao-li'],
//     ['2020/07/02', 'sql-optmize-list-contain-my-post'],
//     ['2020/06/28', 'blog-auto-deploy-bash'],
//     ['2020/05/11', 'mysql-alter-table-with-big-data'],
//     ['2020/04/30', 'phper-gan-wen-lu-zai-he-fang'],
//     ['2020/04/26', 'uncaught-typeerror-cannot-convert-object-to-primitive-value'],
//     ['2020/04/23', 'apple-pay-research'],
//     ['2020/04/04', 'laravel-middleware-filter-params'],
//     ['2020/04/03', 'tips-website-global-grey'],
//     ['2020/03/06', 'rabbitmq-delay-task'],
//     ['2020/01/01', 'faqs-git'],
//     ['2020/01/01', 'faqs-linux'],
//     ['2020/01/01', 'faqs-sql'],
//     ['2020/01/01', 'faqs-php'],
//     ['2019/08/20', 'codeignitor3-x-class-load-process'],
//     ['2019/06/04', 'codeignitor-config-class-tutorial'],
//     ['2019/05/19', 'memory-stack-vs-heap'],
//     ['2019/02/23', 'how-far-can-we-work-to-get-into-graduate-school'],
//     ['2019/03/22', 'codeigniter-tutorial'],
//     ['2018/12/21', 'working-with-php-arrays-in-the-right-way' ],
//     ['2018/11/29', 'understand-laravel-ioc-service-container'],
//     ['2018/10/21', 'error-1698-access-denied-for-user-root-localhost'],
//     ['2018/08/11', 'understand-php-new-static'],
//     ['2018/06/12', 'how-zend-framework-1-start'],
//     ['2018/05/03', 'ssh-key-login-server-and-git'],
//     ['2018/04/19', 'single-php-script-debug-vscode'],
//     ['2018/04/17', 'ubuntu-gnome-cant-enter-desktop'],
//     ['2018/04/05', 'ubuntu-16-04-install-gnome'],
//     ['2018/03/22', 'ubuntu-1604-vscode-c-programming-debug'],
//     ['2018/02/27', 'install-php-in-ubuntu'],
//     ['2017/09/16', 'vscode-xdebug-ignore-notice-breakpoint'],
//     ['2017/09/03', 'it-fatigue-ultimate-guide-the-truth-of-our-industry'],
//     ['2017/08/11', 'enable-apache-rewrite-module-in-ubuntu'],
//     ['2017/06/30', 'how-can-self-taught-programmers-find-good-jobs'],
//     ['2017/01/05', 'zend-framework-1-quick-start'],
//     ['2016/12/22', 'ubuntu-apache24-vhost'],

// --- 生活篇
//     ['2020/06/09', 'nanjing-201905'],
     ['2020/04/12', 'chun-gui-he-chu-si-yue-mu-xiu-qiu-mu-xiang-yi-ji-zi-teng'],
//     ['2020/03/14', '20200314-xuan-wu-hu-spring'],
//     ['2020/02/10', '2020-yi-qing-ge-li-ji'],
//     ['2020/01/05', '2020-weekend-1-activity'],
//     ['2019/12/15', 'autumn-visit-to-qixia'],
//     ['2019/12/05', 'getting-to-know-about-instant-noodles'],
//     ['2019/11/02', 'hang-zhou-two-days'],
//     ['2019/10/20', 'trip-to-hui-zhou-yan-pu-and-mu-li-gong'],
//     ['2019/09/06', 'trip-to-hui-zhou-tai-ping-hu-and-qian-kou-etc'],
//     ['2019/08/25', 'trip-to-hui-zhou-ning-guo-and-qing-long-wan-etc'],
//     ['2019/08/17', 'programmers-cooking-skills-from-scratch'],
//     ['2019/08/03', 'summary-201907'],
//     ['2019/07/09', 'trip-to-hui-zhou-po-shan-and-yang-chan-etc'],
//     ['2019/07/04', 'nanjing-botanical-garde-tropical-plants-gallery'],
//     ['2019/04/30', 'plant-note-201904'],
//     ['2019/02/18', 'night-tour-of-qinhuai-river'],
//
// --- 书影音
//     ['2022/08/03', 'book-yi-ju-ding-yi-wan-ju'],
//     ['2019/01/14', 'movie-white-snake'],
//     ['2021/01/30', 'netease-music-reviews-3'],
//     ['2020/09/21', 'netease-music-reviews-2'],
//     ['2020/09/05', 'music-memory'],
//     ['2020/04/27', '2020-xing-hua-xian-wai-yu'],
//     ['2020/03/14', '20200314-xuan-wu-hu-spring'],
//     ['2020/02/10', 'book-jie-qi-shou-tie'],
//     ['2019/08/03', 'go-go-squi'],
//     ['2019/02/15', 'book-hua-jian-ti-hu-fang-da-chu'],
//     ['2018/11/26', 'gu-jian-qi-tan-3-end-videos'],
//     ['2018/10/28', 'book-wo-de-26-sui-nv-fang-ke'],
//     ['2017/09/16', 'netease-music-reviews'],
//     ['2017/08/23', 'book-sams-teach-yourself-sql-in-10-minutes'],
//     ['2017/02/06', 'book-hackers-and-painters'],
];

foreach ($dir_files as $dir_file) {
    list($dir, $filename) = $dir_file;
    md2html($dir, $filename);
}


function md2html($dir, $filename) {
    $fromFilename = $filename;
    if ($dir) {
        $fromFilename = str_replace('/', '-', $dir) . '-' . trim($filename, '/');
    }
    $inputFile = "my_note_path/{$fromFilename}.md";

    $outputDir = dirname(__DIR__) . "/public/{$dir}";
    if (!file_exists($outputDir)) {
        mkdir($outputDir, 0777, true);
    }

    $outputFile = "{$outputDir}{$filename}.html";
    if ($dir) {
        $outputFile = "{$outputDir}/{$filename}.html";
    }

    $uri = "/blog/{$dir}{$filename}";
    $str = "pandoc --no-highlight --template='tpl.html' -s -o {$outputFile} {$inputFile} --variable=path:{$uri}";

    exec($str);
}