コード例 #1
0
ファイル: sitemap.py プロジェクト: chripo/acrylamid
    def generate(self, conf, env, data):
        """In this step, we filter drafted entries (they should not be included into the
        Sitemap) and write the pre-defined priorities to the map."""

        path = joinurl(conf['output_dir'], self.path)
        sm = Map()

        if exists(path) and not self.modified and not conf.modified:
            event.skip('sitemap', path)
            raise StopIteration

        for ns, fname in self.files:

            if ns == 'draft':
                continue

            permalink = '/' + fname.replace(conf['output_dir'], '')
            url = conf['www_root'] + permalink
            priority, changefreq = self.scores.get(ns, (0.5, 'weekly'))
            if self.imgext:
                images = [x for x in self.mapping.get(permalink, []) if splitext(x)[1].lower() in self.imgext]
                sm.add(rchop(url, 'index.html'), getmtime(fname), changefreq, priority, images)
            else:
                sm.add(rchop(url, 'index.html'), getmtime(fname), changefreq, priority)
        sm.finish()
        yield sm, path
コード例 #2
0
    def generate(self, conf, env, data):
        """In this step, we filter drafted entries (they should not be included into the
        Sitemap) and write the pre-defined priorities to the map."""

        path = joinurl(conf['output_dir'], self.path)
        sm = Map()

        if exists(path) and not self.modified and not conf.modified:
            event.skip('sitemap', path)
            raise StopIteration

        for ns, fname in self.files:

            if ns == 'draft':
                continue

            permalink = '/' + fname.replace(conf['output_dir'], '')
            url = conf['www_root'] + permalink
            priority, changefreq = self.scores.get(ns, (0.5, 'weekly'))
            if self.imgext:
                images = [x for x in self.mapping.get(permalink, []) if splitext(x)[1].lower() in self.imgext]
                sm.add(rchop(url, 'index.html'), getmtime(fname), changefreq, priority, images)
            else:
                sm.add(rchop(url, 'index.html'), getmtime(fname), changefreq, priority)
        sm.finish()
        yield sm, path
コード例 #3
0
ファイル: sitemap.py プロジェクト: t-8ch/acrylamid
    def generate(self, request):
        """In this step, we filter drafted entries (they should not be included into the
        Sitemap) and test each url pattern for success and write the corresponding
        changefreq and priority to the Sitemap."""

        drafted = set([
            joinurl(self.conf['output_dir'], e.permalink, 'index.html')
            for e in request['entrylist'] + request['pages'] if e.draft
        ])

        path = joinurl(self.conf['output_dir'], self.path)
        sm = Map()

        if exists(path) and not self.has_changed:
            event.skip(path)
            raise StopIteration

        for fname in self.files:
            if fname in drafted:
                continue

            url = join(self.conf['www_root'],
                       fname.replace(self.conf['output_dir'], ''))
            for view in self.views:

                if self.patterns[view].match(url):
                    priority, changefreq = self.scores.get(
                        view, (0.5, 'weekly'))
                    sm.add(rchop(url, 'index.html'), getmtime(fname),
                           changefreq, priority)

                    break

        yield sm.read(), path
コード例 #4
0
ファイル: sitemap.py プロジェクト: MeirKriheli/acrylamid
    def generate(self, request):
        """In this step, we filter drafted entries (they should not be included into the
        Sitemap) and test each url pattern for success and write the corresponding
        changefreq and priority to the Sitemap."""

        drafted = set([joinurl(self.conf['output_dir'], e.permalink, 'index.html')
                    for e in request['entrylist'] + request['pages'] if e.draft])

        path = joinurl(self.conf['output_dir'], self.path)
        sm = Map()

        if exists(path) and not self.has_changed:
            event.skip(path)
            raise StopIteration

        for fname in self.files:
            if fname in drafted:
                continue

            url = join(self.conf['www_root'], fname.replace(self.conf['output_dir'], ''))
            for view in self.views:

                if self.patterns[view].match(url):
                    priority, changefreq = self.scores.get(view, (0.5, 'weekly'))
                    sm.add(rchop(url, 'index.html'), getmtime(fname), changefreq, priority)

                    break

        yield sm.read(), path
コード例 #5
0
ファイル: sitemap.py プロジェクト: yegle/acrylamid
    def generate(self, conf, env, data):
        """In this step, we filter drafted entries (they should not be included into the
        Sitemap) and test each url pattern for success and write the corresponding
        changefreq and priority to the Sitemap."""

        drafted = set([joinurl(conf['output_dir'], e.permalink, 'index.html')
            for e in data.get('drafts', [])])

        path = joinurl(conf['output_dir'], self.path)
        sm = Map()

        if exists(path) and not self.modified:
            event.skip(path)
            raise StopIteration

        for fname in self.files:
            if fname in drafted:
                continue

            url = join(conf['www_root'], fname.replace(conf['output_dir'], ''))
            for view in self.views:

                if any(ifilter(lambda pat: pat.match(url), self.patterns[view])):
                    priority, changefreq = self.scores.get(view.name, (0.5, 'weekly'))
                    sm.add(rchop(url, 'index.html'), getmtime(fname), changefreq, priority)

                    break

        sm.finish()
        yield sm, path
コード例 #6
0
ファイル: readers.py プロジェクト: pixelkaiser/acrylamid
    def permalink(self):
        """Actual permanent link, depends on entry's property and ``permalink_format``.
        If you set permalink in the YAML header, we use this as permalink otherwise
        the URL without trailing *index.html.*"""

        try:
            return self.props['permalink']
        except KeyError:
            return expand(rchop(self.props['%s_permalink' % self.type], 'index.html'), self)
コード例 #7
0
ファイル: readers.py プロジェクト: t-8ch/acrylamid
    def permalink(self):
        """Actual permanent link, depends on entry's property and ``permalink_format``.
        If you set permalink in the YAML header, we use this as permalink otherwise
        the URL without trailing *index.html.*"""

        try:
            return self.props['permalink']
        except KeyError:
            return expand(
                rchop(self.props['%s_permalink' % self.type], 'index.html'),
                self)
コード例 #8
0
def w3c(paths, conf, warn=False, sleep=0.2):
    """Validate HTML by using the validator.w3.org API.

    :param paths: a list of HTML files we map to our actual domain
    :param conf: configuration
    :param warn: don't handle warnings as success when set
    :param sleep: sleep between requests (be nice to their API)"""

    for path in paths:
        url = path[len(conf['output_dir']) - 1:]

        resp = head("http://validator.w3.org/check?uri=" + \
            helpers.joinurl(conf['www_root'], quote(url)))

        print helpers.rchop(url, 'index.html'),

        if resp.code != 200:
            print red('not 200 Ok!')
            continue

        headers = resp.info()
        if headers['x-w3c-validator-status'] == "Abort":
            print red("Abort")
        elif headers['x-w3c-validator-status'] == 'Valid':
            if int(headers['x-w3c-validator-warnings']) == 0:
                print green('Ok')
            else:
                if warn:
                    print yellow(headers['x-w3c-validator-warnings'] +
                                 ' warns')
                else:
                    print green('Ok')
        else:
            res = headers['x-w3c-validator-errors'] + ' errors, ' + \
                  headers['x-w3c-validator-warnings'] + ' warns'
            print red(res)

        time.sleep(sleep)
コード例 #9
0
ファイル: check.py プロジェクト: maphew/acrylamid
def w3c(paths, conf, warn=False, sleep=0.2):
    """Validate HTML by using the validator.w3.org API.

    :param paths: a list of HTML files we map to our actual domain
    :param conf: configuration
    :param warn: don't handle warnings as success when set
    :param sleep: sleep between requests (be nice to their API)"""

    for path in paths:
        url = path[len(conf['output_dir'])-1:]

        resp = head("http://validator.w3.org/check?uri=" + \
            helpers.joinurl(conf['www_root'], quote(url)))

        print helpers.rchop(url, 'index.html'),

        if resp.code != 200:
            print red('not 200 Ok!')
            continue

        headers = resp.info()
        if headers['x-w3c-validator-status'] == "Abort":
            print red("Abort")
        elif headers['x-w3c-validator-status'] == 'Valid':
            if int(headers['x-w3c-validator-warnings']) == 0:
                print green('Ok')
            else:
                if warn:
                    print yellow(headers['x-w3c-validator-warnings'] + ' warns')
                else:
                    print green('Ok')
        else:
            res = headers['x-w3c-validator-errors'] + ' errors, ' + \
                  headers['x-w3c-validator-warnings'] + ' warns'
            print red(res)

        time.sleep(sleep)
コード例 #10
0
ファイル: e9.py プロジェクト: acordoba86/evonove.it
    def generate(self, conf, env, data):
        """In this step, we filter drafted entries (they should not be included into the
        Sitemap) and write the pre-defined priorities to the map."""

        path = joinurl(conf['output_dir'], self.path)
        sm = Map()

        if exists(path) and not self.modified:
            event.skip('sitemap', path)
            raise StopIteration

        for ns, fname in self.files:

            if ns == 'draft':
                continue

            url = conf['www_root'] + '/' + fname.replace(conf['output_dir'], '')
            url = strip_default_lang(url, conf)
            priority, changefreq = self.scores.get(ns, (0.5, 'weekly'))
            sm.add(rchop(url, 'index.html'), getmtime(fname), changefreq, priority)

        sm.finish()
        yield sm, path