Пример #1
0
    'authors': False,
    'slug': False
}

METADATA_PROCESSORS = {
    'tags': lambda x, y: ([
        Tag(tag, y)
        for tag in ensure_metadata_list(x)
    ] or _DISCARD),
    'date': lambda x, y: get_date(x.replace('_', ' ')),
    'modified': lambda x, y: get_date(x),
    'status': lambda x, y: x.strip() or _DISCARD,
    'category': lambda x, y: _process_if_nonempty(Category, x, y),
    'author': lambda x, y: _process_if_nonempty(Author, x, y),
    'authors': lambda x, y: ([
        Author(author, y)
        for author in ensure_metadata_list(x)
    ] or _DISCARD),
    'slug': lambda x, y: x.strip() or _DISCARD,
}

logger = logging.getLogger(__name__)


def ensure_metadata_list(text):
    """Canonicalize the format of a list of authors or tags.  This works
       the same way as Docutils' "authors" field: if it's already a list,
       those boundaries are preserved; otherwise, it must be a string;
       if the string contains semicolons, it is split on semicolons;
       otherwise, it is split on commas.  This allows you to write
       author lists in either "Jane Doe, John Doe" or "Doe, Jane; Doe, John"
Пример #2
0
    'tags':
    lambda x, y:
    ([Tag(tag, y) for tag in ensure_metadata_list(x)] or _DISCARD),
    'date':
    lambda x, y: get_date(x.replace('_', ' ')),
    'modified':
    lambda x, y: get_date(x),
    'status':
    lambda x, y: x.strip() or _DISCARD,
    'category':
    lambda x, y: _process_if_nonempty(Category, x, y),
    'author':
    lambda x, y: _process_if_nonempty(Author, x, y),
    'authors':
    lambda x, y:
    ([Author(author, y) for author in ensure_metadata_list(x)] or _DISCARD),
    'slug':
    lambda x, y: x.strip() or _DISCARD,
}

logger = logging.getLogger(__name__)


def ensure_metadata_list(text):
    """Canonicalize the format of a list of authors or tags.  This works
       the same way as Docutils' "authors" field: if it's already a list,
       those boundaries are preserved; otherwise, it must be a string;
       if the string contains semicolons, it is split on semicolons;
       otherwise, it is split on commas.  This allows you to write
       author lists in either "Jane Doe, John Doe" or "Doe, Jane; Doe, John"
       format.
Пример #3
0
    from cgi import escape
from six.moves.html_parser import HTMLParser

from pelican import signals
from pelican.contents import Page, Category, Tag, Author
from pelican.utils import get_date, pelican_open, FileStampDataCacher, SafeDatetime, posixize_path

METADATA_PROCESSORS = {
    'tags': lambda x, y: [Tag(tag, y) for tag in x.split(',')],
    'date': lambda x, y: get_date(x.replace('_', ' ')),
    'modified': lambda x, y: get_date(x),
    'status': lambda x, y: x.strip(),
    'category': Category,
    'author': Author,
    'authors':
    lambda x, y: [Author(author.strip(), y) for author in x.split(',')],
}

logger = logging.getLogger(__name__)


class BaseReader(object):
    """Base class to read files.

    This class is used to process static files, and it can be inherited for
    other types of file. A Reader class must have the following attributes:

    - enabled: (boolean) tell if the Reader class is enabled. It
      generally depends on the import of some dependency.
    - file_extensions: a list of file extensions that the Reader will process.
    - extensions: a list of extensions to use in the reader (typical use is
Пример #4
0
    r"(?P<metadata>.+?)"
    r"^(?:---|\.\.\.)$"
    r"(?P<content>.*)", re.MULTILINE | re.DOTALL)

DUPES_NOT_ALLOWED = \
    set(k for k, v in DUPLICATES_DEFINITIONS_ALLOWED.items() if not v) - \
    {"tags", "authors"}

_DEL = object()

YAML_METADATA_PROCESSORS = {
    'tags': lambda x, y: [Tag(_strip(t), y) for t in _to_list(x)] or _DEL,
    'date': lambda x, y: _parse_date(x),
    'modified': lambda x, y: _parse_date(x),
    'category': lambda x, y: Category(_strip(x), y) if x else _DEL,
    'author': lambda x, y: Author(_strip(x), y) if x else _DEL,
    'authors':
    lambda x, y: [Author(_strip(a), y) for a in _to_list(x)] or _DEL,
    'slug': lambda x, y: _strip(x) or _DEL,
    'save_as': lambda x, y: _strip(x) or _DEL,
    'status': lambda x, y: _strip(x) or _DEL,
}


def _strip(obj):
    return str(obj if obj is not None else '').strip()


def _to_list(obj):
    """Make object into a list"""
    return [obj] if not isinstance(obj, list) else obj
Пример #5
0
    def replacer(siteurl, m):
        what = m.group('what')
        value = urlparse(m.group('value'))
        path = value.path
        origin = m.group('path')

        # XXX Put this in a different location.
        if what in {'filename', 'attach'}:
            if path.startswith('/'):
                path = path[1:]
            else:
                # relative to the source path of this content
                path = content.get_relative_source_path(
                    os.path.join(content.relative_dir, path))

            if path not in content._context['filenames']:
                unquoted_path = path.replace('%20', ' ')

                if unquoted_path in content._context['filenames']:
                    path = unquoted_path

            linked_content = content._context['filenames'].get(path)
            if linked_content:
                if what == 'attach':
                    if isinstance(linked_content, Static):
                        linked_content.attach_to(content)
                    else:
                        logger.warning(
                            "%s used {attach} link syntax on a "
                            "non-static file. Use {filename} instead.",
                            content.get_relative_source_path())
                origin = '/'.join((siteurl, linked_content.url))
                origin = origin.replace('\\', '/')  # for Windows paths.
            else:
                logger.warning(
                    "Unable to find `%s`, skipping url replacement.",
                    value.geturl(),
                    extra={
                        'limit_msg': ("Other resources were not found "
                                      "and their urls not replaced")
                    })
        elif what == 'category':
            origin = '/'.join((siteurl, Category(path, content.settings).url))
        elif what == 'tag':
            origin = '/'.join((siteurl, Tag(path, content.settings).url))
        elif what == 'index':
            origin = '/'.join((siteurl, content.settings['INDEX_SAVE_AS']))
        elif what == 'author':
            origin = '/'.join((siteurl, Author(path, content.settings).url))
        else:
            logger.warning(
                "Replacement Indicator '%s' not recognized, "
                "skipping replacement", what)

        # keep all other parts, such as query, fragment, etc.
        parts = list(value)
        parts[2] = origin
        origin = urlunparse(parts)

        return ''.join(
            (m.group('markup'), m.group('quote'), origin, m.group('quote')))
Пример #6
0
def _process_if_nonempty(processor, name, settings):
    """Removes extra whitespace from name and applies a metadata processor.
    If name is empty or all whitespace, returns _DISCARD instead.
    """
    name = name.strip()
    return processor(name, settings) if name else _DISCARD


METADATA_PROCESSORS = {
    'tags': lambda x, y: [Tag(tag, y) for tag in strip_split(x)] or _DISCARD,
    'date': lambda x, y: get_date(x.replace('_', ' ')),
    'modified': lambda x, y: get_date(x),
    'status': lambda x, y: x.strip() or _DISCARD,
    'category': lambda x, y: _process_if_nonempty(Category, x, y),
    'author': lambda x, y: _process_if_nonempty(Author, x, y),
    'authors': lambda x, y: [Author(a, y) for a in strip_split(x)] or _DISCARD,
    'slug': lambda x, y: x.strip() or _DISCARD,
}


def _filter_discardable_metadata(metadata):
    """Return a copy of a dict, minus any items marked as discardable."""
    return {name: val for name, val in metadata.items() if val is not _DISCARD}


logger = logging.getLogger(__name__)


class BaseReader(object):
    """Base class to read files.
Пример #7
0
except ImportError:
    from HTMLParser import HTMLParser

from pelican import signals
from pelican.contents import Page, Category, Tag, Author
from pelican.utils import get_date, pelican_open


METADATA_PROCESSORS = {
    'tags': lambda x, y: [Tag(tag, y) for tag in x.split(',')],
    'date': lambda x, y: get_date(x),
    'modified': lambda x, y: get_date(x),
    'status': lambda x, y: x.strip(),
    'category': Category,
    'author': Author,
    'authors': lambda x, y: [Author(author, y) for author in x],
}

logger = logging.getLogger(__name__)


class BaseReader(object):
    """Base class to read files.

    This class is used to process static files, and it can be inherited for
    other types of file. A Reader class must have the following attributes:

    - enabled: (boolean) tell if the Reader class is enabled. It
      generally depends on the import of some dependency.
    - file_extensions: a list of file extensions that the Reader will process.
    - extensions: a list of extensions to use in the reader (typical use is