美文网首页网站博客
Typecho博客搭建

Typecho博客搭建

作者: CSeroad | 来源:发表于2019-12-02 12:50 被阅读0次

前言

自从搭建了onedrive网盘后,就想着再搭建了博客了。个人比较喜欢简洁的Typecho模板,也支持markdown语法,可以将简书的文章同步到Tyecho博客上。

搭建

搭建起来比较简单
下载Typecho源码放到宝塔,配置域名进行访问即可。具体操作参考 Onedrive搭建个人网盘

image.png

按照操作创建config.inc.php文件,并赋予权限。

升级

先进行升级,为了更好的适用于插件。
参考文章更新 Typecho 1.1

image.png

主题

Typecho有许多好看使用的主题。Typecho 主题:修改方法及优秀主题推荐

尝试使用的是Maupassant极简主题,从github上进行下载
https://github.com/pagecho/maupassant/

下载到Typecho/usr/themes目录下。

外观

查看网站外观,可切换外观。

插件

为了方便操作、浏览,我用了许多插件。

image.png

依次介绍一下。

Parsedown插件

高效的markdown解析插件。github地址

Paste Image插件

优秀的图片上传插件
可以直接截图后粘贴。github地址

image.png

TinyPNG 插件

发现网页在加载图片时比较缓慢,TinyPNG 插件可以在上传图片的时候对其进行压缩,缩小图片大小,加开访问速度。配合Paste Image插件可谓方便之极。
参考文章一款图片压缩插件《TinyPNG for Typecho》
需要申请TinyPNG ApiKey后在后台配置。

附加
原本的想法是写段php代码,将简书的图片下载到本地后,再将数据库的text字段的图片外链地址改为本地链接地址。但是在代码写出后,发现图片下载下来特别大,即使经过optipng命令进行压缩后还是比较大。所以这个方法就夭折了,采用了插件。

<?php 
$curl = curl_init();
$con = mysqli_connect('localhost', 'typecho', 'x2P3r2tNxxxx','typecho');//数据库信息修改为你自己的数据库账号信息
$sql = "select * from typecho_contents where type = 'post' order by cid asc";//jq_contents修改为你的数据库中的contents表名称
$result = mysqli_query($con,$sql);
$row=mysqli_fetch_assoc($result);

preg_match_all('/https:\/\/upload-images.jianshu.io\/.*.(jpg|png).*\d+/', $row['text'], $matche);
//var_dump($matche);
preg_match_all('/https:\/\/upload-images.jianshu.io\/.*.(jpg|png)/', $row['text'], $matches);
//var_dump($matches);

$local_date =  date('Y-m-d', $row['created']);
$arr_date = explode('-', $local_date);

foreach($matches[0] as $k=>$pic){
    //var_dump($matches[0]);
    echo $matches[0][$k];
    curl_setopt($curl, CURLOPT_URL, $matches[0][$k]);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT,0);
    $data = curl_exec($curl);
    $ret = file_put_contents(dirname(__FILE__)."/usr/uploads/".$arr_date[0]."/".$arr_date[1]."/".$arr_date[2]."/".$k.".".$matches[1][$k], $data);
    //print_r(dirname(__FILE__)."/usr/uploads/".$arr_date[0]."/".$arr_date[1]."/".$arr_date[2]."/".$k.".".$matches[1][$k]." ret:$ret<br />");
    $old_img_path = $matche[0][$k];
    echo $old_img_path;
    $new_img_path = "http://cseroad.xyz/usr/uploads/".$arr_date[0]."/".$arr_date[1]."/".$arr_date[2]."/".$k.".".$matches[1][$k];
    $row['text'] = str_replace($old_img_path, $new_img_path, $row['text']);
}
//echo $row['text'];

$newtext = mysqli_real_escape_string($con,$row['text']);
$sql3 = "UPDATE `typecho_contents` SET  `text` =  '$newtext' where cid=".$row['cid'];
//echo $sql3;
mysqli_query($con,$sql3);
mysqli_close($con);
curl_close($curl);

Views插件

来统计浏览次数。
参考文章
Typecho 浏览统计插件Views使用方法
Typecho文章浏览次数统计设置
文章里包含下载地址。

只显示摘要

在修改外观处,找到archive.php和index.php页面。
content(...);替换为excerpt(300,'...');

image.png

修改typecho首页显示文章的数量
function.php页面末尾增加以下代码

function themeInit($archive) {
    if ($archive->is('index')) {
        $archive->parameter->pageSize = 6;
    }
}

加固

博客搭建也需要一些简单加固。

删除登录功能

如删除sidebar.php页面的登录功能。


image.png

修改后台地址

修改config.inc.php的后台路径,并对admin目录进行重命名。
删除index.html、install.php、install文件。

结尾

优化到这暂时可以浏览使用了,以后有需求再加吧。
blog地址为 http://cseroad.xyz

相关文章

  • Typecho 主题修改方法 & 优秀主题推荐

    前言 上一篇已经介绍过如何搭建自己的 Typecho 博客(30分钟搭建 Typecho 博客),博客搭建完成自带...

  • [Typecho] 个人使用资源整理

    Typecho 博客基本搭建完成,这里整理一些相关资源,各取所需。 插件: AMP for Typecho 这是款...

  • Typecho博客搭建

    说明 我使用的服务器: 服务器:https://bandwagonhost.com/ 服务器系统:Debian 8...

  • Typecho博客搭建

    前言 自从搭建了onedrive网盘后,就想着再搭建了博客了。个人比较喜欢简洁的Typecho模板,也支持mark...

  • Hexo 搭建博客

    上一篇文章 阿里云虚拟机下搭建Typecho、WordPress博客 简单的记录了Typecho、WordPre...

  • 使用typecho搭建轻量级博客系统

    本文介绍使用Debian(stretch)+nginx(1.10)+typecho+sqlite3搭建轻量级博客系...

  • [Typecho] 博客搭建过程

    之前博主有用 hexo 静态博客,近期本着想折腾折腾的想法,换成博客平台。目前博客平台是比较多的,其中 WordP...

  • Ubuntu搭建Typecho博客

    我用的是腾讯云服务器安装的镜像是公共镜像Ubuntu Server 14.04.1 更新apt-get:sudo ...

  • Linux搭建Typecho博客

    购买服务器 推荐服务器:雨云服务器价格比较实惠,而且选用香港服务器还可以免备案,可以用积分续费,这样能省不少钱。雨...

  • Vultr+Namesilo+宝塔+Typecho搭建个人博客

    Vultr+Namesilo+宝塔+Typecho搭建个人博客 购买Vultr服务器 Vultr网址:vultr....

网友评论

    本文标题:Typecho博客搭建

    本文链接:https://www.haomeiwen.com/subject/kxewwctx.html