def postprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Generating Atom feeds..") cls._generate_atom_feed(root, virtual_fs, root.subdir_by_name("en").changelog) cls._generate_atom_feed(root, virtual_fs, root.subdir_by_name("cz").changelog)
def preprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Removing dull notion.so table files..") for dir in root.walk_dirs(): if dir.filename.startswith( "Interesting_articles") and dir.parent is root: cls._empty_directory(dir) for page in root.walk_htmls(): page_body_tags = page.dom.find("div", {"class": "page-body"}) if page_body_tags and not page_body_tags[0].getContent().strip(): page.parent.files.remove(page)
def preprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Converting Changelog table to readable page..") en_changelog = Changelog(root.subdir_by_name("Changelog"), virtual_fs.resource_registry) en_changelog.feed_name = "atom.xml" root.subdir_by_name("en").changelog = en_changelog cz_changelog = Changelog(root.subdir_by_name("Zmeny"), virtual_fs.resource_registry) cz_changelog.feed_name = "atom_cz.xml" root.subdir_by_name("cz").changelog = cz_changelog
def postprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Adding sidebars to all pages..") for page in root.walk_htmls(): if not page.is_embeddable: page.sidebar = None continue if page.sidebar is not None: page.sidebar.add_to_page(page)
def postprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Converting twitter cards to abs url..") for page in root.walk_htmls(): for meta in page.dom.find("meta", {"name": "twitter:image"}): resource_id_token = meta.params["content"] if not ResourceRegistry.is_ref_str(resource_id_token): continue resource = virtual_fs.resource_registry.item_by_ref_str( resource_id_token) abs_path = cls._to_abs_url_path(resource.path) meta.params["content"] = abs_path
def preprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Unfucking filenames..") for item in root.walk_htmls(): if item.filename == "index.html": continue title = item.title if "://" in title: continue new_filename = cls._normalize_fn(title) new_filename = cls._trim_long_filenames(new_filename) new_filename = cls._make_sure_filename_is_unique(item, new_filename) if new_filename: cls._rename_also_section_dirs(item, new_filename) item.filename = new_filename + ".html" for item in root.walk_dirs(): new_filename = cls._unfuck_filename(item.filename) item.filename = cls._make_sure_filename_is_unique(item, new_filename)
def preprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Collecting tags..") registry = virtual_fs.resource_registry Tags._collect_tags(root) settings.logger.info("Generating tag structure..") for root_section in root.get_root_sections(): tag_to_ref_str_map = cls._generate_tag_structure( root, registry, root_section.tags) settings.logger.info("Putting taglist to pages with tags..") cls._add_tags_to_all_pages(root_section.tags, tag_to_ref_str_map)
def preprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Squashing toplevel directory..") root_index = root.files[0] root_index.filename = "index.html" # squash toplevel directory, as it holds only index blog_subdir = root.subdirs[0] root.subdirs = blog_subdir.subdirs root.files = blog_subdir.files root.files.append(root_index) root.reindex_parents() root.inner_index = root_index root.outer_index = root_index
def _generate_tag_structure(cls, root, registry, tag_manager): tag_directory = Directory(tag_manager.dirname) tag_to_ref_str_map = {} for tag, subpages in sorted(tag_manager.tag_dict.items()): links = cls._yield_links_to_subpages(registry, subpages) tag_page_html = TAG_PAGE_TEMPLATE.format(tag_name=tag, links="\n".join( list(links))) tag_page = HtmlPage(tag_page_html, tag + ".html") tag_page.alt_title = tag tag_directory.add_file(tag_page) tag_ref_str = registry.register_item_as_ref_str(tag_page) tag_to_ref_str_map[tag] = tag_ref_str links = [] for tag, tag_ref in tag_to_ref_str_map.items(): no_items = len(tag_manager.tag_dict[tag]) no_tags = "(%s items)" if no_items > 1 else "(%s item)" links.append( LINK_TEMPLATE.format(page_name=tag, ref_str=tag_ref, no_tags=no_tags % no_items, description="")) tag_index_html = TAG_INDEX_TEMPLATE.format(links="\n".join(links)) tag_index_outer = HtmlPage(tag_index_html, "%s.html" % tag_manager.dirname) tag_index_outer.alt_title = tag_manager.alt_title root.add_subdir(tag_directory) root.add_file(tag_index_outer) tag_directory.add_copy_as_index(tag_index_outer) return tag_to_ref_str_map
def preprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Renaming `English_section/` to `en/` and " "`Czech_section/` to `cz/`.") root.subdirs = list(cls._reindex_dirs(root))
def preprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Converting all spaces in names to underscores..") for item in root.walk_all(): item.filename = item.filename.replace(" ", "_") item.filename = item.filename.replace("%20", "_")
def tree(): root = Directory("/") subdir = Directory("subdir") root.add_subdir(subdir) subdir.parent = root file_in_root = HtmlPage("<body><img src='subdir/img.jpg' /></body>", "file_in_root.html") root.add_file(file_in_root) file_in_root.parent = root file_in_subdir = HtmlPage( "<body><a href='../file_in_root.html'>asd</a></body>", 'file_in_subdir.html') subdir.add_file(file_in_subdir) file_in_subdir.parent = subdir image_in_subdir = Data('/subdir/img.jpg', 'IMG_CONTENT') subdir.add_file(image_in_subdir) image_in_subdir.parent = subdir return root
def preprocess(cls, virtual_fs: VirtualFS, root: Directory): settings.logger.info("Collecting ref links to all pages..") registry = virtual_fs.resource_registry for page in root.walk_htmls(): cls._collect_from(page, registry)