Gmeek icon indicating copy to clipboard operation
Gmeek copied to clipboard

上传css、js等等到docs目录,但是会被删。

Open molikai-work opened this issue 8 months ago • 6 comments

试着将代码改成下面这样,能保留自行上传的文件或文件夹,但是可能维护不方便,因为指定了只处理固定的文件或文件夹, 关于操作文件夹的部分。

    def __init__(self, options):
        self.options = options

        self.root_dir = 'docs/'
        self.post_folder = 'post/'
        self.backup_dir = 'backup/'
        self.post_dir = self.root_dir + self.post_folder

        user = Github(self.options.github_token)
        self.repo = self.get_repo(user, options.repo_name)
        self.feed = FeedGenerator()
        self.oldFeedString = ''

        self.labelColorDict = json.loads('{}')
        for label in self.repo.get_labels():
            self.labelColorDict[label.name] = '#' + label.color
        print(self.labelColorDict)

        self.defaultConfig()

    def cleanFile(self):
        workspace_path = os.environ.get('GITHUB_WORKSPACE')

        if os.path.exists(workspace_path + "/" + self.root_dir):
            self.clean_root_dir(workspace_path + "/" + self.root_dir)

        if os.path.exists(self.root_dir):
            self.clean_root_dir(self.root_dir)

        os.makedirs(self.post_dir, exist_ok=True)

    def clean_root_dir(self, root_dir):
        delete_files = {'index.html', 'postList.json', 'rss.xml', 'tag.html'}
        delete_dirs = {'post'}
        for item in os.listdir(root_dir):
            item_path = os.path.join(root_dir, item)
            if item in delete_files:
                if os.path.isfile(item_path):
                    os.remove(item_path)
            elif item in delete_dirs:
                if os.path.isdir(item_path):
                    shutil.rmtree(item_path)

molikai-work avatar Jun 21 '24 03:06 molikai-work