html使用网络图片防盗问题解决

解决mkdocs图片防盗问题

前言

我在mkdocs上的图片是使用博客园上的,部署后无法正常显示。度娘了一下,只用在<head>后插入<meta name="referrer" content="no-referrer" />

写脚本

  • @遍历所在目录及其目录下所有的html文件,在第8行追加代码
# coding:utf-8
import os

def get_files(path='D:zyt\azytsfx', rule=".sfx"):
    all = []
    for fpathe,dirs,fs in os.walk(path):   # os.walk获取所有的目录
        for f in fs:
            filename = os.path.join(fpathe,f)
            if filename.endswith(rule):  # 判断是否是".sfx"结尾
                all.append(filename)
    return all

def file_insert(path, lenth,rule, string):
    lines = []
    with open(path, encoding='UTF-8') as f:
        lines = f.readlines()
    f.close()

    if lines != []:
        if rule in lines[lenth]:
            print('已经有了')
        else:
            with open(path, 'w', encoding='UTF-8') as f:
                print('插入行')
                lines.insert(lenth,string)
                f.writelines(lines)
            f.close()

htmlpath = get_files(r".", rule=".html")
for i in htmlpath:
    print(i)
    file_insert(i,7,r'referrer',r'<meta name="referrer" content="no-referrer" />')

实现效果

image

image

原文地址:https://www.cnblogs.com/yywBlogW/p/11375694.html