Liquid 字符串连接

将两个字符串连接在一起,Liquid 不能直接使用连接符号,例如其它语言里的“+”加号。
而是使用 append 这个 filter。

举例:
{% assign text = "a" | append: "b" %}

{% assign x = 'abc' %}
{% assign y = 'def' %}
{% assign z = x | append: ' - ' | append: y %}
{{ z }}

output: abc - def

macOS 如何一键快速锁屏

macOS 系统默认的锁屏快捷键: Control + Command + Q⌃⌘Q

由于退出应用的快捷键是 ⌘Q,和锁屏快捷键差别一个组合键,有可能按错导致退出当前应用。可考虑使用触发角快速锁屏。

Liquid 获取数组或字符串的长度

size 返回字符串中所包含的字符数或者数组中所包含的条目数量。size 还支持“点标记”。举例:

过滤器方式:

{{ my_array | size }}

使用“点标记”:

{% if site.pages.size > 10 %}
  This is a big website!
{% endif %}

Python 自动给重名文件名添加序号

检查给定的文件路径是否已经重名,并自动添加序号,递增数字。

Code on Github Gist

def auto_rename_exist_filename(file_path):
    """
    For example: a.txt, a(1).txt, a(2).txt
    Source: https://gist.github.com/nodewee/9ae9b0b461b4bcaf30bc2b84ca8c4743.js
    """
    if not os.path.exists(file_path):
        return file_path

    dir_path = os.path.dirname(file_path)
    src_filename = os.path.basename(file_path)
    [file_title, ext_name] = os.path.splitext(src_filename)

    pattern = r"\((\d+?)\)$"
    r = re.search(pattern, file_title)
    if r:
        serial = str(int(r.groups()[0]) + 1)
        new_title = re.sub(pattern, "(" + serial + ")", file_title)
    else:
        new_title = file_title + "(1)"

    new_filepath = os.path.join(dir_path, new_title + ext_name)

    if os.path.exists(new_filepath):
        return auto_rename_exist_filename(new_filepath)
    else:
        return new_filepath