How to use the pelican.contents.Page function in pelican

To help you get started, we’ve selected a few pelican examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ingwinlu / pelican-bootstrapify / test_bootstrapify.py View on Github external
<p></p>
        <p></p>
        <p></p>
        <a href=""></a>
        <a class="menu" href=""></a>
        <table></table>
        <table id="bootstrapThis"></table>
        <img href="">
        
        """

        settings = get_settings()
        settings['BOOTSTRAPIFY'] = {'p:nth-of-type(3)': ['third'],
                                    'a.menu': ['btn', 'btn-lg'],
                                    'table[id]': ['table', 'table-striped']}
        content = Page(content=html_doc, settings=settings)
        bootstrapify(content)

        soup = BeautifulSoup(content._content, 'html.parser')

        self.assertEqual(soup.select('p')[0].attrs.keys(), [])
        self.assertEqual(soup.select('p')[1].attrs.keys(), [])
        self.assertItemsEqual(soup.select('p')[2].attrs['class'], ['third'])
        self.assertEqual(soup.select('a')[0].attrs.keys(), ['href'])
        self.assertItemsEqual(soup.select('a')[1].attrs['class'],
                              ['menu', 'btn', 'btn-lg'])
        self.assertEqual(soup.select('table')[0].attrs.keys(), [])
        self.assertItemsEqual(soup.select('table')[1].attrs['class'],
                              ['table', 'table-striped'])
        self.assertEqual(soup.select('table')[1].attrs['id'], 'bootstrapThis')
github ingwinlu / pelican-bootstrapify / test_bootstrapify.py View on Github external
def test_settings(self):
        html_doc = """
        
        <p></p>
        <a href=""></a>
        <table></table>
        <img class="testing" href="">
        
        """

        settings = get_settings()
        settings['BOOTSTRAPIFY'] = {'p': ['pclass'],
                                    'a': ['aclass1', 'aclass2']}
        content = Page(content=html_doc, settings=settings)
        bootstrapify(content)

        soup = BeautifulSoup(content._content, 'html.parser')

        self.assertItemsEqual(soup.select('p')[0].attrs['class'], ['pclass'])
        self.assertItemsEqual(soup.select('a')[0].attrs['class'],
                              ['aclass1', 'aclass2'])
        self.assertItemsEqual(soup.select('img')[0].attrs['class'],
                              ['testing'])
github ingwinlu / pelican-bootstrapify / test_bootstrapify.py View on Github external
def test_default(self):
        html_doc = """
        
        <p></p>
        <a href=""></a>
        <table></table>
        <img href="">
        
        """

        content = Page(content=html_doc, settings=get_settings())
        bootstrapify(content)

        soup = BeautifulSoup(content._content, 'html.parser')

        self.assertItemsEqual(soup.select('table')[0].attrs['class'],
                              ['table', 'table-striped', 'table-hover'])
        self.assertItemsEqual(soup.select('img')[0].attrs['class'],
                              ['img-responsive'])
        self.assertEqual(soup.select('p')[0].attrs.keys(), [])
        self.assertEqual(soup.select('a')[0].attrs.keys(), ['href'])
github ingwinlu / pelican-bootstrapify / test_bootstrapify.py View on Github external
def test_append_class(self):
        html_doc = """
        
        <p></p>
        <a href=""></a>
        <table></table>
        <img class="testing" href="">
        
        """

        content = Page(content=html_doc, settings=get_settings())
        bootstrapify(content)

        soup = BeautifulSoup(content._content, 'html.parser')

        self.assertItemsEqual(soup.select('table')[0].attrs['class'],
                              ['table', 'table-striped', 'table-hover'])
        self.assertItemsEqual(soup.select('img')[0].attrs['class'],
                              ['testing', 'img-responsive'])
        self.assertEqual(soup.select('p')[0].attrs.keys(), [])
        self.assertEqual(soup.select('a')[0].attrs.keys(), ['href'])
github mawenbao / pelican-blog-content / plugins / sitemap / sitemap.py View on Github external
def write_url(self, page, fd):

        if getattr(page, 'status', 'published') != 'published':
            return

        page_path = os.path.join(self.output_path, page.url)
        if not os.path.exists(page_path):
            return

        lastmod = format_date(getattr(page, 'updatedate', getattr(page, 'date', self.now)))

        if isinstance(page, contents.Article):
            pri = self.priorities['articles']
            chfreq = self.changefreqs['articles']
        elif isinstance(page, contents.Page):
            pri = self.priorities['pages']
            chfreq = self.changefreqs['pages']
        else:
            pri = self.priorities['indexes']
            chfreq = self.changefreqs['indexes']


        if self.format == 'xml':
            fd.write(XML_URL.format(self.siteurl, page.url, lastmod, chfreq, pri))
        else:
            fd.write(self.siteurl + '/' + loc + '\n')
github grupydf / grupydf.github.io / .plugins / sitemap / sitemap.py View on Github external
page_path = os.path.join(self.output_path, page.save_as)
        if not os.path.exists(page_path):
            return

        lastdate = getattr(page, 'date', self.now)
        try:
            lastdate = self.get_date_modified(page, lastdate)
        except ValueError:
            warning("sitemap plugin: " + page.save_as + " has invalid modification date,")
            warning("sitemap plugin: using date value as lastmod.")
        lastmod = format_date(lastdate)

        if isinstance(page, contents.Article):
            pri = self.priorities['articles']
            chfreq = self.changefreqs['articles']
        elif isinstance(page, contents.Page):
            pri = self.priorities['pages']
            chfreq = self.changefreqs['pages']
        else:
            pri = self.priorities['indexes']
            chfreq = self.changefreqs['indexes']

        pageurl = '' if page.url == 'index.html' else page.url
        
        #Exclude URLs from the sitemap:
        sitemapExclude = []

        if self.format == 'xml':
            if pageurl not in sitemapExclude:
                fd.write(XML_URL.format(self.siteurl, pageurl, lastmod, chfreq, pri))
        else:
            fd.write(self.siteurl + '/' + pageurl + '\n')
github AlexJF / pelican-entities / entities.py View on Github external
settings['CATEGORY_URL'] = entity_type_lower + '/category/{slug}.html'
    settings['CATEGORY_SAVE_AS'] = os.path.join(entity_type_lower, 'category', '{slug}.html')
    #settings['TAG_TEMPLATE'] = 'tag'
    settings['TAG_URL'] = entity_type_lower + '/tag/{slug}.html'
    settings['TAG_SAVE_AS'] = os.path.join(entity_type_lower, 'tag', '{slug}.html')
    #settings['AUTHOR_TEMPLATE'] = 'author'
    settings['AUTHOR_URL'] = entity_type_lower + '/author/{slug}.html'
    settings['AUTHOR_SAVE_AS'] = os.path.join(entity_type_lower, 'author', '{slug}.html')

    settings['DIRECT_TEMPLATES'] = []
    settings['PAGINATED_DIRECT_TEMPLATES'] = []

    return settings


class Entity(contents.Page):
    pass


def EntityFactory(name, mandatory_properties, default_template, BaseClass=Entity):
    base_mandatory_properties = ['title']
    mandatory_properties = set(base_mandatory_properties + mandatory_properties)
    newclass = type(str(name), (BaseClass,),
                    {'type': name,
                     'mandatory_properties': mandatory_properties,
                     'default_template': default_template})
    return newclass


class EntityGenerator(generators.Generator):
    """ Generate entity pages for each defined entity type."""
github akhayyat / pelican-page-hierarchy / page_hierarchy.py View on Github external
def override_metadata(content_object):
    if type(content_object) is not contents.Page:
        return
    page = content_object
    path = get_path(page, page.settings)

    def _override_value(page, key):
        metadata = copy(page.metadata)
        # We override the slug to include the path up to the filename
        metadata['slug'] = os.path.join(path, page.slug)
        # We have to account for non-default language and format either,
        # e.g., PAGE_SAVE_AS or PAGE_LANG_SAVE_AS
        infix = '' if in_default_lang(page) else 'LANG_'
        return page.settings['PAGE_' + infix + key.upper()].format(**metadata)

    for key in ('save_as', 'url'):
        if not hasattr(page, 'override_' + key):
            setattr(page, 'override_' + key, _override_value(page, key))
github iksteen / pelican-albums / pelican_albums / generator.py View on Github external
class ImageContent(object):
    def __init__(self, album, filename, settings):
        self.album = album
        self.filename = filename
        self.settings = settings
        self.page = None

    @property
    def url(self):
        return self.album.url + '/' + self.filename

    def thumbnail(self, spec=''):
        return thumbnails.request_thumbnail(os.path.join(self.album.name, self.filename), spec, self.settings)


class Image(Page):
    default_template = 'image'
    image = None

    @property
    def prev(self):
        return self._prev_next(operator.sub)

    @property
    def next(self):
        return self._prev_next(operator.add)

    def _prev_next(self, op):
        images = self.image.album.images
        index = images.index(self.image)
        prev_index = op(index, 1) % len(images)
        return images[prev_index].page
github iksteen / pelican-albums / pelican_albums / generator.py View on Github external
    @property
    def url(self):
        return (self.settings['ALBUM_PATH'] + '/' + self.name) if self.name else self.settings['ALBUM_PATH']

    def add_image(self, filename):
        image = ImageContent(self, filename, self.settings)
        self._images[filename] = image
        return image

    @property
    def images(self):
        return [self._images[image] for image in sorted(self._images.keys())]


class Album(Page):
    default_template = 'album'
    album = None

    @property
    def cover_image(self):
        try:
            # Cover set through page metadata.
            filename = self.cover
        except AttributeError:
            cover = self.album.images[0]
        else:
            cover = self.album._images[filename]
        return cover


class AlbumGenerator(Generator):