Beispiel #1
0
    def test_check_extension(self):
        valid_files = ['/tmp/file1.md', '/tmp/file2.mkd', '/tmp/文件3.mdown',
                       '/tmp/文件4.markdown', '/tmp/目录/文件5.md']
        for f in valid_files:
            assert utils.check_extension(f)

        invalid_files = ['/tmp/file6.txt', '/tmp/目录/文件7.mkdown']
        for f in invalid_files:
            assert not utils.check_extension(f)
Beispiel #2
0
    def test_check_extension(self):
        valid_files = [
            '/tmp/file1.md', '/tmp/file2.mkd', '/tmp/文件3.mdown',
            '/tmp/文件4.markdown', '/tmp/目录/文件5.md'
        ]
        for f in valid_files:
            assert utils.check_extension(f)

        invalid_files = ['/tmp/file6.txt', '/tmp/目录/文件7.mkdown']
        for f in invalid_files:
            assert not utils.check_extension(f)
Beispiel #3
0
    def get_tpl_vars(self):
        """
        XXX: Only for one level dir.
        """
        catalog_page_list = {}

        sub_dirs = [ _ for _ in os.listdir(self.site_settings["source"])]
        for sub_dir in sub_dirs:
            abs_sub_dir = osp.join(self.site_settings["source"], sub_dir)
            if not osp.isdir(abs_sub_dir):
                continue
            catalog_page_list[sub_dir] = []
            for f in os.listdir(abs_sub_dir):
                if not utils.check_extension(f):
                    continue
                fn = osp.join(abs_sub_dir, f)
                meta_yaml, contents = self.get_meta_and_content(fn)
                meta_datas = self.get_meta_datas(meta_yaml, fn)
                r, e = osp.splitext(f)
                meta_datas.update(name = r)
                catalog_page_list[sub_dir].append(meta_datas)
            catalog_page_list[sub_dir].sort(
                key=lambda d: datetime.datetime.strptime(
                    d["date"], "%Y-%m-%d %H:%M"
                ),
                reverse=True,
            )

        tpl_vars = {
            "site" : self.site_settings,
            "catalog" : catalog_page_list,
        }

        return tpl_vars
Beispiel #4
0
    def __get_catalog_page_list(self, d):
        """
        XXX: Only for root and one level dir.
        """
        catalog_page_list = {}
        sub_dirs = [unicode(_, "utf-8") for _ in \
                utils.listdir_nohidden(d)]
        for sub_dir in sub_dirs:
            abs_sub_dir = osp.join(self.site_settings["source"], sub_dir)
            # If file under the root of content directory, ignore it.
            # TODO: support root level.
            if not osp.isdir(abs_sub_dir):
                continue
            catalog_page_list[sub_dir] = []
            for f in utils.listdir_nohidden(abs_sub_dir):
                if osp.isdir(f):
                    catalog_page_list[sub_dir][f] = {}
                if not utils.check_extension(f):
                    continue
                fn = osp.join(abs_sub_dir, f)
                pg = PageGenerator(self.site_settings, self.base_path, fn)
                metadata, _ = pg.get_metadata_and_content()
                r, e = osp.splitext(f)
                metadata.update(name = r)
                catalog_page_list[sub_dir].append(metadata)
            catalog_page_list[sub_dir].sort(
                key = lambda p: p["title"].lower()
            )

        return catalog_page_list
Beispiel #5
0
    def generate_all_pages(self):
        logger.info("Start generating markdown files.")
        content_path = self.configs["source"]

        pcnt = 0
        for root, dirs, files in os.walk(content_path):
            for filename in files:
                if not check_extension(filename):
                    continue
                md_file = osp.join(root, filename)
                self.generate_single_page(md_file)
                pcnt += 1
        logger.info("{} files generated.".format(pcnt))
Beispiel #6
0
    def generate_all_pages(self):
        logger.info("Start generating markdown files.")
        content_path = self.configs["source"]

        pcnt = 0
        for root, dirs, files in os.walk(content_path):
            files = [f for f in files if not f.decode("utf-8").startswith(".")]
            dirs[:] = [d for d in dirs if not d.decode("utf-8").startswith(".")]
            for filename in files:
                if not check_extension(filename):
                    continue
                md_file = osp.join(root, filename)
                self.generate_single_page(md_file)
                pcnt += 1
        logger.info("{} files generated.".format(pcnt))
Beispiel #7
0
 def test_check_extension(self):
     file1 = "/tmp/file1.md"
     file2 = "/tmp/file2.mkd"
     file3 = "/tmp/test/文件3.mdown"
     file4 = "/var/lib/file4.markdown"
     file5 = "/tmp/testfile"
     file6 = "/tmp/wrong.mkdown"
     file7 = "/tmp/文件7.mkdown"
     assert utils.check_extension(file1)
     assert utils.check_extension(file2)
     assert utils.check_extension(file3)
     assert utils.check_extension(file4)
     assert not utils.check_extension(file5)
     assert not utils.check_extension(file6)
     assert not utils.check_extension(file7)
Beispiel #8
0
 def test_check_extension(self):
     file1 = "/tmp/file1.md"
     file2 = "/tmp/file2.mkd"
     file3 = "/tmp/test/文件3.mdown"
     file4 = "/var/lib/file4.markdown"
     file5 = "/tmp/testfile"
     file6 = "/tmp/wrong.mkdown"
     file7 = "/tmp/文件7.mkdown"
     assert utils.check_extension(file1)
     assert utils.check_extension(file2)
     assert utils.check_extension(file3)
     assert utils.check_extension(file4)
     assert not utils.check_extension(file5)
     assert not utils.check_extension(file6)
     assert not utils.check_extension(file7)
Beispiel #9
0
    def generate_all_pages(self):
        logger.info("Start generating markdown files.")
        content_path = self.configs["source"]

        pcnt = 0
        pages = {}
        for root, dirs, files in os.walk(content_path):
            files = [f for f in files if not f.decode("utf-8").startswith(".")]
            dirs[:] = [
                d for d in dirs if not d.decode("utf-8").startswith(".")
            ]
            for filename in files:
                if not check_extension(filename):
                    continue
                md_file = osp.join(root, filename)
                pages[md_file] = self.generate_single_page(md_file)
                pcnt += 1
        logger.info("{} files generated.".format(pcnt))
        return pages