How to use the pelican.utils.slugify 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 AcrDijon / henet / henet / views / article.py View on Github external
article['body'] = data.get('content', DEFAULT_BODY)
    date = datetime.datetime.now()
    article.set_metadata('date', date)

    if page is None:
        # it's an article
        cat_info = dict(app.vars['categories'])[category]
        article.set_metadata('category', cat_info['title'])
        path = cat_info['path']
    else:
        # it's a page
        path = dict(app.vars['pages'])[page]['path']

    # XXX we might want to put it under the year directory
    i = 1
    filename = slugify(article['title'])
    fullfilename = os.path.join(path, filename)
    while os.path.exists(fullfilename + '.rst'):
        fullfilename += str(i)
        i += 1

    with open(fullfilename + '.rst', 'w') as f:
        f.write(article.render().encode('utf8'))

    emit(EVENT_CREATED_CONTENT, article_path=fullfilename)
    if page is None:
        redirect('/category/%s/%s' % (category, filename + '.rst'))
    else:
        redirect('/page/%s/%s' % (page, filename + '.rst'))
github fjcaetano / pelican_admin / pelican_admin / models / blog_post.py View on Github external
def get_slug(self):
        if not self.slug:
            self.slug = slugify(self.title)

        return self.slug
github pyvideo / pyvideo / plugins / event_info.py View on Github external
def _load_events():
    path = Path('content') / 'conferences'
    events = {}
    slugs = set()
    for metafile in path.glob('*/category.json'):
        # skip the schema "category.json" file
        if metafile.parent and metafile.parent.name.startswith('.'):
            continue
        with open(str(metafile), encoding='utf-8') as fp:
            data = json.load(fp)
            title = data['title']
            slug = slugify(title)
            if data.get('description'):
                data['description'] = _generate_html(data['description'])
            if title in events:
                log.critical('{} is not a unique category title!'.format(title))
            if slug in slugs:
                log.critical('{} is not a unique slug!'.format(slug))
            slugs.add(slug)
            events[title] = data
    return events
github cmacmackin / scribbler / scribbler / notebook.py View on Github external
def newpage(self, title, markup='md'):
        """
        Create a new page ("appendix") with the specified title. Returns
        the path to the page file.
        """
        MARKUP_OPTIONS = {
            'md': "Title: {0}\n\n",
            'rst': "{0}\n###################\n\n",
            'html': "\n\t\n\t\t<title>{0}</title>\n\t"
                    "\n\t\n\t\t\n\t\n\n",
        }
        name = slugify(title)
        for ext in MARKUP_OPTIONS:
            if os.path.isfile(os.path.join(self.location,self.APPE_DIR,
                              name + '.' + ext)):
                raise ScribblerError('Date and name produce slug the '
                                     'same as existing file ' + name +
                                     '.' + ext)
        basename = name + '.' + markup
        path = os.path.join(self.location, self.APPE_DIR, basename)
        out = open(path, 'w')
        try:
            out.write(MARKUP_OPTIONS[markup].format(title))
            out.close()
        except KeyError as e:
            out.close()
            os.remove(path)
            raise e
github AcrDijon / henet / henet / views / category.py View on Github external
def set_extra_info(article):
        data = {'date': article['metadata']['date'],
                'slug': slugify(article['title'])}
        article['url'] = article_url.format(**data)
        article_filename = os.path.join(cat_path, article['filename'])
        article_uuid = article_filename[len(content_root) + 1:]
        comments = comments_database.get_comments(article_uuid=article_uuid)
        article['comments_count'] = len(list(comments))
        return article
github AcrDijon / henet / henet / views / page.py View on Github external
def set_extra_info(article):
        data = {'date': article['metadata']['date'],
                'slug': slugify(article['title'])}
        article['url'] = page_url.format(**data)
        return article
github fjcaetano / pelican_admin / pelican_admin / models / blog_post.py View on Github external
def get_from_meta(cls, markup, title=None, slug=None):
        content_path = os.path.join(settings.PELICAN_PATH, 'content')

        if isinstance(markup, int):
            markup = MARKUPS[markup][1]

        if slug:
            file_path = os.path.join(content_path, slug+'.'+markup)
            try:
                result = BlogPost.objects.get(file_path=file_path)
                return result
            except BlogPost.DoesNotExist:
                pass

        if title:
            file_path = os.path.join(content_path, slugify(title)+'.'+markup)
            try:
                result = BlogPost.objects.get(file_path=file_path)
                return result
            except BlogPost.DoesNotExist:
                pass

        raise BlogPost.DoesNotExist()
github pyvideo / pyvideo / bin / article_maker.py View on Github external
title_line = self.title.replace('*', '\*')
        lines.append(title_line)
        lines.append('#' * len(bytes(title_line.encode())))
        lines.append('')  # add extra line break after title

        # build meta data section
        lines.append(':date: {}'.format(self.date))

        if self.modified_date:
            lines.append(':modified: {}'.format(self.modified_date))

        if self.tags:
            lines.append(':tags: {}'.format(', '.join(self.tags)))

        lines.append(':category: {}'.format(self.category))
        lines.append(':slugified_category: {}'.format(slugify(self.category)))

        #lines.append(':slug: {}'.format(slugify(self.title)))

        authors_string = ', '.join(self.authors) or 'Unknown'
        lines.append(':authors: {}'.format(authors_string))

        # The RstReader has trouble reading metadata strings that
        # contain underscores, even if those underscores are escaped with
        # backslashes. Thus, underscores are escaped here with a string.
        # Real underscores are re-introduced by the replace_underscore
        # plugin defined in bin/plugins.
        thumbnail_url = self.media_thubmnail_url.replace('_', 'UNDERSCORE')
        lines.append(':thumbnail_url: {}'.format(thumbnail_url))

        media_url = self.media_url.replace('_', 'UNDERSCORE')
        lines.append(':media_url: {}'.format(media_url))