Total Pageviews

Wednesday 6 November 2024

kaf-cli

 把txt文本转成epub和mobi电子书的命令行工具.

 https://ystyle.top/2019/12/31/txt-converto-epub-and-mobi/

把txt文本转成epub电子书的命令行工具

功能

  • 傻瓜操作模式(把txt文件拖到kaf-cli.exe上面自动转换)
  • 自定义封面
  • 支持生成Orly风格的书籍封面
  • 自动识别书名和章节(示例中所有用法都会自动识别)
  • 自动识别字符编码(自动解决中文乱码)
  • 自定义章节标题识别规则
  • 自定义卷的标题识别规则
  • 自动给章节正文生成加粗居中的标题
  • 自定义标题对齐方式
  • 段落自动识别
  • 段落自动缩进
  • 自定义段落缩进字数
  • 自定义段落间距
  • 自定义行间距
  • 自定义书籍语言
  • epub格式支持嵌入字体
  • 知轩藏书格式文件名会自动提取书名和作者, 例: 《希灵帝国》(校对版全本)作者:远瞳.txt
  • 超快速(130章/s以上速度, 4000章30s不到)
  • 自动转为mobi格式

下载

使用方法

  1. 解压, 把小说直接拖到 kaf-cli.exe 文件上面
  2. 等转换完,目录下会生成epub、azw3、mobi文件
    • mobi格式需要有kindlegen才会生成(windows、mac版本已经自带)
  3. 自定义封面功能 在拖拽模式下, 如果目录下有cover.png文件会自动添加为封面、支持jpg、png格式, 如果需要指定其它文件或jpg格式需要使用命令行模式
  4. 其它自定义功能请用命令行模式

效果

效果图片 效果图片

命令行模式参数

Usage of kaf-cli:
  -align string
        标题对齐方式: left、center、righ。环境变量KAF_CLI_ALIGN可修改默认值 (default "center")
  -author string
        作者 (default "YSTYLE")
  -bookname string
        书名: 默认为txt文件名
  -bottom string
        段落间距(单位可以为em、px) (default "1em")
  -cover string
        封面图片可为: 本地图片, 和orly。 设置为orly时生成orly风格的封面, 需要连接网络。 (default "cover.png")
  -cover-orly-color string
        orly封面的主题色, 可以为1-16和hex格式的颜色代码, 不填时随机
  -cover-orly-idx int
        orly封面的动物, 可以为0-41, 不填时随机, 具体图案可以查看: https://orly.nanmu.me (default -1)
  -filename string
        txt 文件名
  -font string
        嵌入字体, 之后epub的正文都将使用该字体
  -format string
        书籍格式: all、epub、mobi、azw3。环境变量KAF_CLI_FORMAT可修改默认值 (default "all")
  -indent uint
        段落缩进字数 (default 2)
  -lang string
        设置语言: en,de,fr,it,es,zh,ja,pt,ru,nl。环境变量KAF_CLI_LANG可修改默认值 (default "en")
  -line-height string
        行高(用于设置行间距, 默认为1.5rem)
  -match string
        匹配标题的正则表达式, 不写可以自动识别, 如果没生成章节就参考教程。例: -match 第.{1,8}章 表示第和章字之间可以有1-8个任意文字
  -max uint
        标题最大字数 (default 35)
  -out string
        输出文件名,不需要包含格式后缀
  -tips
        添加本软件教程 (default true)
  -unknow-title string
        未知章节默认名称 (default "章节正文")
  -volume-match string
        卷匹配规则 (default "^第[0-9一二三四五六七八九十零〇百千两 ]+[卷部]")

PS: 在darwin(mac、osx)上-tips参数要设置为false的方法 kaf-cli -filename 小说.txt -tips=0

命令行模式说明

转换全职法师.txt, 并设置作者名为

# windows 10: win + s 搜索powershell 
cd d:/
d:/kaf-cli.exe -author 乱 -filename d:/全职法师.txt

# linux / mac下, 把kaf-cli-linux/kaf-cli-darwin重命名为kaf-cli, 放到用户目录
# 把小说和kaf-cli放到用户目录下,  打开终端执行
cd ~
./kaf-cli -author 乱 -filename ./全职法师.txt

# 如果kaf-cli放到path里了, 或者在aur安装的可以执行:
kaf-cli -author 乱 -filename ~/全职法师.txt

# 命令行的简单模式(功能和拖拽模式一样)
kaf-cli ~/全职法师.txt

自定义章节匹配规则

以下全部示例都可以自动识别,不需要自己设定标题格式了, 一般用上用上面的例子就行了

规则支持正则表达式, 要自定义标题格式参考以下几个例子, 以下例子小说都在D盘

自定义章节匹配, 章节格式为第x节:

d:/kaf-cli.exe -filename d:/ebbok.txt -match "第.{1,8}节"

自定义章节匹配, 章节格式为Section 1 ~ Section 100:

d:/kaf-cli.exe -filename d:/ebbok.txt -match "Section \d+"

自定义章节匹配, 章节格式为Chapter xxx:

d:/kaf-cli.exe -filename d:/ebbok.txt -match "Chapter .{1,8}"

在任意位置执行命令

  • windows
    • kaf-cli.exekindlegen.exec:/windows/下边
    • 以后可以把小说放任意目录,都可以很简单执行转换, 第一步只需要做一次, 以下为每次转换小说的操作,
      • 打开小说在的文件夹, 按住Shift键不放,鼠标右击文件夹空白位置
      • 在右键菜单选择 用命令行打开以PowerShell打开
      • 以上命令可以改为 kaf-cli.exe -filename 全职法师.txt, 现在可以不用写盘符了
  • linux(理论上mac也可以是这样的)
    • 软件可以放任意地方, 比如~/application/kaf-cli,在~/.bashrc~/.zshrc 最后一行添加 export PATH=$HOME/application:$PATH
    • 打开终端, 执行命令为: kaf-cli -filename ~/全职法师.txt

手动把书转为kindle的mobi格式

新版如果检测到有kindlegen程序时会自动转为mobi

  1. 下载kindlegen (github备份,官网已经不提供下载)
  2. 同样放到d:盘根目录下, 把epub拖拽到kindlegen.exe上面, 或执行以下命令转换
cd d:/
d:/kindlegen.exe d:/全职法师.epub
  1. 在d盘就能找到mobi文件,复制到kindle的documents目录下,打开kindle就能看到小说了.

from https://github.com/ystyle/kaf-cli

 

Tuesday 5 November 2024

Build Your Own Static Site Generator

Static site generators are fairly popular tools these days for creating websites. Static site generators typically work by taking a collection of markdown files and converting them into HTML files using templates, and are generally geared towards blogs (although they can be used to create just about any site or portion thereof). These generators represent a middle ground between manually creating an entire website from scratch in HTML and using a CMS such as Wordpress while retaining significant advantages over each option:

  1. As their name implies, they generate static websites, meaning the files can be served and cached very easily by servers with virtually no processing required
  2. They don’t come with security issues (unlike wordpress) because there isn’t any code being executed on the server (other than delivering the raw files of course)
  3. They make it much easier to author content than writing HTML directly, as you typically write in Markdown instead of HTML
  4. They make styling much easier than writing HTML directly, as you can write templates (for example using Jinja or Handlebars so you only have to edit one file to change the layout of all the pages on the site).

Why Write Your Own Generator?

If you take a look at https://www.staticgen.com/ you’ll see there are already a ton of static website generators out there—so why bother writing your own? For me, this glut of generators gives me two problems:

  1. With thousands to choose from, how do I narrow it down to one that works exactly how I want without investing a few weeks evaluating a bunch of the options?
  2. These generators were all written with other peoples’ use cases in mind—option A may feature Jinja templates but not syntax highlighting while option B may require a custom template language but does have syntax highlighting, etc.

Again, given just how many static site generators exist, you could probably find one that works well enough for you. The thing is—you don’t have to, as it turns out its rather easy to write your own static site generator that is built exactly for your exact use case. Even though I have developed tons of projects of this scope (and larger), it never occurred to me to write my own generator until I got curious about how the excellent Game Programming Patterns website was generated and took a look at the source. I encourage you to take a look at the repository—everything is straight-to-the-point, and only what is absolutely required to build the site is present.

Ultimately, the thing I like the most about writing your own generator is that you can customize it for yourself exactly the way you want! For example, my generator renders KaTeX equations at compile time so my site works 100% without Javascript, it compiles plantuml diagrams from inline code in the source to inline svg elements, it renders syntax using Pygments, and it uses Commonmark with several extensions instead of plain Markdown, and it uses Tera templates. I wrote the generator with all its bells and whistles in a few hours, which is way less time than I would have spent browsing https://www.staticgen.com/ to find something with those exact features that I wanted.

Writing Your Own Generator

The script to generate the website for Game Programming Patterns is in format.py, and aside from a few custom things thrown in in order to build navigation and wrangle the styling, the process boils down to the following:

  1. Find all files that end in .markdown in the source folder
  2. Format each .markdown file into an .html file
  3. Do secondary tasks such as re-compile the stylesheets and calculate a word count for the entire book

Really, all we need to do is get a list of files in a directory, get the contents of each file (both things that will be included in the standard library of pretty much any programming language), and format each file using your markdown library of choice. While Bob Nystrom used Python for generating Game Programming Patterns, if you’re writing your own generator you can use any language you want! For this website, I am currently using Rust (because why not?), and the process is basically the same (with a few bells and whistles thrown in along the way):

  1. I get the list of .md files in the posts folder
  2. I format each file into a .html version and save it to disk
  3. I generate the index by rendering an index template
  4. I copy over all static assets to the output directory

In my sources, I make use of YAML frontmatter—that is, each .md post starts with a block of text which describes meta-data about the post (this is fairly common in static site generators). It is fairly easy to parse, but using frontmatter certainly isn’t required—the magic of writing your own generator is that you get to do whatever you want!

Downsides To Creating Your Own Generator

Of course, creating your own generator for each site isn’t the be-all, end-all solution to all of your problems. The first, most obvious downside is that you actually have to write the damned thing in the first place (rather than just downloading some framework and using that). I would argue that unless you have no programming experience, this isn’t as big a hurdle as you might expect (I would further argue that writing a generator is a great programming project to introduce you to programming in general, or for picking up a new language).

Going down this route can also lend itself to a rather excessive amount of yak shaving if you’re not careful. This can be somewhat mitigated by ensuring you only include features you absolutely need right now (not what you think you might need someday in the future). In other words, just don’t shave the yak, you dummy 😉.

Another downside is that since you’ve effectively started a new project, there is no one else to maintain it—you can’t just run your package manager to pull in new features and bug fixes. You’re not just the boss, but the accountant and the janitor and everyone in between. This shouldn’t be a huge deal given the rather small scope and complexity of a static site generator, but it is something to be aware of.

There are other downsides that you may run into if you decide to go down this path, but in my opinion these don’t outweigh the positives of doing so. The best judge will be yourself, and I encourage you to take an afternoon to whip up something simple for your existing blog or whatever content you have laying around to get a sense of just how straightforward this can be.

A Template To Start From

To help you get started writing your own generator, here is a simple Python script that can serve as a jumping off point:

#!/usr/bin/env python3
import os
import glob
import markdown

if not os.path.exists('public'):
    os.mkdir('public')

for f in glob.iglob('book/*.md'):
    with open(f, 'r') as file:
        raw = file.read()
        html = markdown.markdown(raw)

    file_name = os.path.basename(f)
    destination = os.path.join("public", os.path.splitext(file_name)[0] + ".html")

    with open(destination, 'w') as file:
        file.write(r'''<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>My Great Site</title>
</head>
<body>
''')
        file.write(html)
        file.write(r'''
</body>
</html>''')

This script does the bare minimum:

  1. It collects each .md file in the book directory
  2. It parses the markdown and converts it to html
  3. It writes the result out with a minimal template to the public directory

There are a ton of places you can take this small starting point—you can use a proper templating engine (though you don’t have to), generate an index, manage assets, add metadata to each file, etc. The nice thing is that you only need to add what you want!

from  https://blog.hamaluik.ca/posts/build-your-own-static-site-generator/

-----


探秘 Pingora:Cloudflare 的高效静态网站生成器

 

高效的内容处理

Pingora 使用 Markdown 解析器,支持 YAML 头信息,可以方便地处理结构化数据,如博客文章、项目描述等。此外,它还支持自定义模板引擎,允许开发者根据需求定制页面布局和样式。

 动态功能集成

虽然生成的是静态网站,但 Pingora 支持与动态服务(如 API)集成,实现了静态站点与动态数据的完美结合。这种特性在构建如在线商店、实时博客等应用时非常有用。

安全性

作为一个来自 Cloudflare 的项目,安全性是其核心关注点之一。Pingora 提供了内置的安全措施,包括对模板注入的防护,确保你的站点免受常见攻击。

应用场景

  • 个人博客 - 快速搭建一个响应式、高性能的博客平台。
  • 企业官网 - 创建专业且易于维护的企业网站,展示产品和服务。
  • 文档管理系统 - 为开源项目或内部团队构建简洁清晰的文档库。
  • 电子商务 - 结合动态后端实现轻量级电商站点,提高加载速度和用户体验。

特点总结

  1. 高性能 - 利用 Go 语言的优势,构建出快速加载的静态页面。
  2. 易用性 - 简单的配置文件和Markdown支持,让内容创作变得简单。
  3. 高度可定制 - 自定义模板和插件系统适应各种需求。
  4. 安全可靠 - 内置的安全特性保护你的站点不受恶意攻击。
  5. 无缝集成 - 可与API和其他动态服务协同工作,增加功能性。

如果你正在寻找一款现代、强大而又易于使用的静态网站生成工具,那么 Pingora 绝对值得尝试!立即访问 ,开始你的静态网站构建之旅吧!

---------------------

What is Pingora

Pingora is a Rust framework to build fast, reliable and programmable networked systems.

Pingora is battle tested as it has been serving more than 40 million Internet requests per second for more than a few years.

Feature highlights

  • Async Rust: fast and reliable
  • HTTP 1/2 end to end proxy
  • TLS over OpenSSL, BoringSSL or rustls(experimental).
  • gRPC and websocket proxying
  • Graceful reload
  • Customizable load balancing and failover strategies
  • Support for a variety of observability tools

Reasons to use Pingora

  • Security is your top priority: Pingora is a more memory safe alternative for services that are written in C/C++
  • Your service is performance-sensitive: Pingora is fast and efficient
  • Your service requires extensive customization: The APIs Pingora proxy framework provides are highly programmable

Getting started

See our quick starting guide to see how easy it is to build a load balancer.

Our user guide covers more topics such as how to configure and run Pingora servers, as well as how to build custom HTTP servers and proxy logic on top of Pingora's framework.

API docs are also available for all the crates.

Notable crates in this workspace

  • Pingora: the "public facing" crate to build networked systems and proxies
  • Pingora-core: this crate defines the protocols, functionalities and basic traits
  • Pingora-proxy: the logic and APIs to build HTTP proxies
  • Pingora-error: the common error type used across Pingora crates
  • Pingora-http: the HTTP header definitions and APIs
  • Pingora-openssl & pingora-boringssl: SSL related extensions and APIs
  • Pingora-ketama: the Ketama consistent algorithm
  • Pingora-limits: efficient counting algorithms
  • Pingora-load-balancing: load balancing algorithm extensions for pingora-proxy
  • Pingora-memory-cache: Async in-memory caching with cache lock to prevent cache stampede
  • Pingora-timeout: A more efficient async timer system
  • TinyUfo: The caching algorithm behind pingora-memory-cache

System requirements

Systems

Linux is our tier 1 environment and main focus.

We will try our best for most code to compile for Unix environments. This is for developers and users to have an easier time developing with Pingora in Unix-like environments like macOS (though some features might be missing)

Windows support is preliminary by community's best effort only.

Both x86_64 and aarch64 architectures will be supported.

Rust version

Pingora keeps a rolling MSRV (minimum supported Rust version) policy of 6 months. This means we will accept PRs that upgrade the MSRV as long as the new Rust version used is at least 6 months old.

Our current MSRV is 1.72.

Build Requirements

Some of the crates in this repository have dependencies on additional tools and libraries that must be satisfied in order to build them:

  • Make sure that Clang is installed on your system (for boringssl)
  • Make sure that Perl 5 is installed on your system (for openssl)

from https://github.com/cloudflare/pingora

 

搭建基于rust的静态博客程序onepage

 如果你的本地机器是windows os,则参考此文安装rust的windows版 来安装rust的windows版。然后运行git-bash.exe,在程序窗口里输入:

cd ~

cargo install onepage

onepage init onepage-site (此命令会在当前目录下,生成子目录onepage-site)

cd onepage-site

onepage build (这就是生成/更新静态网站的根目录的命令,会在当前目录下,生成dist目录)

cd dist && python3 -m http.server 1234

新建源帖:

cd ..

cd pages/posts

nano hf.md

cat hf.md

显示:

---
title: 快乐的节日
date: 2024-11-05 23:06:39
tags:
  - life
  - music
---

此处写正文或html codes.

cd ~/onepage-site 

$ onepage build

演示网站:

https://blog.nexts.top/

https://melodic-granita-885337.netlify.app/

项目地址:https://github.com/hanpei/onepage

 
 

 

 

 

 

  

安装rust的windows版

下载https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe (from https://www.rust-lang.org/tools/install)

安装时,显示:

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  C:\Users\12799\.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  C:\Users\12799\.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  C:\Users\12799\.cargo\bin

This path will then be added to your PATH environment variable by
modifying the HKEY_CURRENT_USER/Environment/PATH registry key.

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

...

stable-x86_64-pc-windows-msvc installed - rustc 1.82.0 (f6e511eec 2024-10-15)

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload its PATH environment variable to include
Cargo's bin directory (%USERPROFILE%\.cargo\bin).

Press the Enter key to continue.

https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/,


https://learn.microsoft.com/en-us/cpp/build/walkthrough-compiling-a-native-cpp-program-on-the-command-line?view=msvc-170&redirectedfrom=MSDN



linux vps安装SNMP+监控宝

 安装snmpd,

apt-get install snmpd

配置snmpd

停止snmpd服务: /etc/init.d/snmpd stop

创建只读的snmpv3用户: net-snmp-config --create-snmpv3-user -ro -A $PASSWORD -X privpassword $USERNAME #把USERNAME换成你要创建的用户名,$PASSWORD换成你要使用的密码。

修改非127.0.0.1访问

用VIM或是其它编辑器打开 /etc/default/snmpd文件,修改

SNMPDOPTS='-lSD -lF /dev/null -u snmp -I -smux -p /var/run/snmp.pid 127.0.0.1'

删除 127.0.0.1,之后-->

SNMPDOPTS='-lSD -lF /dev/null -u snmp -I -smux -p /var/run/snmp.pid'

OK,如果开了iptables,请:

iptables -A INPUT -i eth0 -p udp -s 125.76.229.215 --dport 161 -j ACCEPT

iptables -A INPUT -i eth0 -p udp -s 60.195.249.83 --dport 161 -j ACCEPT

有关在监控宝中添加服务器监控,请到:

http://blog.jiankongbao.com/?p=160 《在Linux服务器上开启安全的SNMP代理》

xrdp:开源远程桌面协议(RDP)服务器


项目主页:http://xrdp.sourceforge.net/

以下是项目介绍: 基于 rdesktop,xrdp使用远程桌面协议提出一个图形用户界面给用户

该项目目标是提供一个全功能的Linux终端服务器(RDP),客户能够从接受连接rdesktop和Windows中的终端服务器/远程桌面。 不同于Windows NT/2000/2003/2008中的终端服务器,xrdp不会显示Windows桌面,但会提供一个X窗口桌面给用户。 Xrdp使用Xvnc或X11rdp管理X会话。

要了解有关xrdp如何工作,请点击 设计这里

如有问题或意见,请邮件 xrdp-devel@lists.sourceforge.net

该项目是下发布的GNU公共许可证(GPL)。

在Debian中安装很方便 :sudo apt-get install xdrp 然后就可以用rdesktop或Windows 远程协助来连接了.