当前位置: 首页>>代码示例>>Python>>正文


Python Page.copy方法代码示例

本文整理汇总了Python中pages.Page.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Page.copy方法的具体用法?Python Page.copy怎么用?Python Page.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pages.Page的用法示例。


在下文中一共展示了Page.copy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_index_page

# 需要导入模块: from pages import Page [as 别名]
# 或者: from pages.Page import copy [as 别名]
def new_index_page(page_to_copy, page_num, count, total_posts, posts_per_page, path):
    index_page = Page()
    index_page.copy(page_to_copy)
    index_page.url = '/' + path + '/index-%s' % count
    index_page.template = template.get_template('post.html')

    apply_filter('page-head', index_page)
    apply_filter('page-meta', index_page)
    apply_filter('page-menu', index_page)
    apply_filter('page-foot', index_page)

    total_pages = math.ceil(total_posts / posts_per_page) - 1

    if page_num > 0:
        index_page.template.set_value('prevpage', '<< Newer posts')
        if page_num - 1 == 0:
            index_page.template.set_attribute('prevpage', 'href', 'index.html')
        else:
            index_page.template.set_attribute('prevpage', 'href', 'index-%s.html' % (page_num - 1))

    if page_num < total_pages:
        index_page.template.set_value('nextpage', 'Older posts >>')
        index_page.template.set_attribute('nextpage', 'href', 'index-%s.html' % (page_num + 1))

    if page_num > 0 and page_num < total_pages:
        index_page.template.set_value('pagelinksep', ' | ')

    index_page.template.repeat('posts', min(posts_per_page, total_posts - count))
    return index_page
开发者ID:jasonrbriggs,项目名称:sitebaker,代码行数:31,代码来源:blog_plugin.py

示例2: process_path

# 需要导入模块: from pages import Page [as 别名]
# 或者: from pages.Page import copy [as 别名]
def process_path(path, output_path, pages):
    sorted_posts = sorted(filter_pages(path, pages.values()), key=lambda x: x.url[len(path)+1:len(path)+11], reverse=True)
    total_posts = len(sorted_posts)

    if total_posts == 0:
        return

    posts_per_page = get_posts_per_page(sorted_posts)

    count = 0
    page_num = 0
    index = 0

    if path.startswith('/'):
        path = path[1:]

    index_page = new_index_page(sorted_posts[0], page_num, count, total_posts, posts_per_page, path)

    do_action('post-meta-reset')
    for page in sorted_posts:
        cpage = Page()
        cpage.copy(page)
        cpage.template = index_page.template

        # TODO: this isn't right, need to fix later
        apply_filter('pre-markdown', cpage)

        content = apply_filter('markdown', page.content)

        cpage.template.set_value('content', content, index)
        apply_filter('post-meta', cpage, index)
        index += 1
        count += 1
        if index >= posts_per_page:
            write_index_page(index_page, output_path, path, page_num)
            do_action('post-meta-reset')
            index = 0
            page_num += 1
            index_page = new_index_page(sorted_posts[0], page_num, count, total_posts, posts_per_page, path)

    if index > 0:
        write_index_page(index_page, output_path, path, page_num)
开发者ID:jasonrbriggs,项目名称:sitebaker,代码行数:44,代码来源:blog_plugin.py

示例3: process_pages

# 需要导入模块: from pages import Page [as 别名]
# 或者: from pages.Page import copy [as 别名]
def process_pages(pages, output_path):
    root_page = get_root_page(pages)
    if not root_page:
        return pages

    index_title = root_page.config.get('tags', 'index_title')
    tag_title = root_page.config.get('tags', 'title')

    tags = {}

    print('Generating tag index pages')
    for page in pages.values():
        if 'tags' in page.headers:
            for tag in split_tags(page.headers['tags']):
                tag = sanitise_tag(tag)
                if tag not in tags:
                    tags[tag] = []
                tags[tag].append(page)

    tag_dir = os.path.join(output_path, 'tags')

    if not os.path.exists(tag_dir):
        os.makedirs(tag_dir)

    for fname in os.listdir(tag_dir):
        os.remove(os.path.join(tag_dir, fname))

    for tag in tags:
        tmp = template.get_template('tag.html')
        print('  - generating tag %s' % tag)

        output_name = os.path.join(tag_dir, '%s.html' % tag)

        tmp.repeat('posts', len(tags[tag]))
        x = 0
        do_action('post-meta-reset')
        for page in sorted(tags[tag], key=lambda x: x.last_modified, reverse=False):
            cpage = Page()
            cpage.copy(page)
            cpage.template = tmp
            tmp.set_value('content', page.get_html_content(include_title=True), x)
            apply_filter('post-meta', cpage, x)
            x += 1

        apply_filter('page-head', cpage)
        apply_filter('page-meta', cpage)
        apply_filter('page-menu', cpage)
        apply_filter('page-foot', cpage)

        tmp.set_value('page-title', tag_title % tag)
        tmp.set_value('tag', tag_title % tag)
        
        apply_filter('tag-page', cpage)

        out = str(tmp)
        f = open(output_name, 'w+')
        f.write(out)
        f.close()

    tag_counts = {k: len(v) for k, v in tags.items()}

    tag_classes = {}
    page = next(iter(pages.values()))
    for (name, value) in page.config.items('tags'):
        if name.isdigit():
            tag_classes[name] = value

    tmp = template.get_template('tags.html')
    if tmp is None:
        return

    tmp.repeat('tags', len(tags))
    x = 0
    for tag in sorted(tags):
        tmp.set_value('tag', tag, x)
        tmp.set_attribute('tag', 'href', '/tags/%s.html' % tag, x)
        count = tag_counts[tag]

        for key in sorted(tag_classes, reverse=True):
            if count >= int(key):
                tmp.set_attribute('tag', 'class', tag_classes[key], x)
        x += 1

    cpage = Page()
    cpage.copy(page)
    cpage.template = tmp
    apply_filter('page-head', cpage)
    apply_filter('page-meta', cpage)
    apply_filter('page-menu', cpage)
    apply_filter('page-foot', cpage)

    tmp.set_value('page-title', index_title)
    
    apply_filter('tags-index-page', cpage)

    output_name = os.path.join(tag_dir, 'index.html')
    f = open(output_name, 'w+')
    f.write(str(tmp))
    f.close()

#.........这里部分代码省略.........
开发者ID:jasonrbriggs,项目名称:sitebaker,代码行数:103,代码来源:tags_plugin.py


注:本文中的pages.Page.copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。