コード例 #1
0
    def write_index(self):
        old_index_md5 = None

        baseurl = self.normalize_url(conf.get_url(self.site))
        parts = []

        # Collect all pages and write them.
        for section, site in self.sitemaps.items():
            if callable(site):
                pages = site().paginator.num_pages
            else:
                pages = site.paginator.num_pages

            for page in range(1, pages + 1):
                filename = conf.FILENAME_TEMPLATE % {
                    'section': section,
                    'page': page
                }
                lastmod = self.write_page(site, page, filename)

                if conf.USE_GZIP:
                    filename += '.gz'

                parts.append({
                    'location': '%s%s' % (baseurl, filename),
                    'lastmod': lastmod
                })

        path = os.path.join(conf.ROOT_DIR, self.site.domain, 'sitemap.xml')
        self.out('Writing index file.', 2)

        if self.storage.exists(path):
            old_index_md5 = self.read_hash(path)
            self.storage.delete(path)

        output = loader.render_to_string(conf.INDEX_TEMPLATE,
                                         {'sitemaps': parts})
        self._write(path, output)

        with self.storage.open(path) as sitemap_index:
            if self.get_hash(sitemap_index.read()) != old_index_md5:
                self.has_changes = True

        if conf.PING_GOOGLE and self.has_changes:
            try:
                sitemap_url = reverse('static_sitemaps_index')
            except NoReverseMatch:
                sitemap_url = "%ssitemap.xml" % baseurl

            self.out('Pinging google...', 2)
            ping_google(sitemap_url)
コード例 #2
0
    def write_index(self):
        old_index_md5 = None

        baseurl = self.normalize_url(conf.get_url())
        parts = []

        # Collect all pages and write them.
        for section, site in self.sitemaps.items():
            if callable(site):
                pages = site().paginator.num_pages
            else:
                pages = site.paginator.num_pages

            for page in range(1, pages + 1):
                filename = conf.FILENAME_TEMPLATE % {'section': section,
                                                     'page': page}
                lastmod = self.write_page(site, page, filename)

                if conf.USE_GZIP:
                    filename += '.gz'

                parts.append({
                    'location': '%s%s' % (baseurl, filename),
                    'lastmod': lastmod
                })

        filename = 'sitemap.xml'
        self.out('Writing index file.', 2)

        if self.storage.exists(filename):
            old_index_md5 = self.read_hash(filename)
            self.storage.delete(filename)

        output = loader.render_to_string(conf.INDEX_TEMPLATE, {'sitemaps': parts})
        self._write(filename, output)

        with self.storage.open(filename) as sitemap_index:
            if self.get_hash(sitemap_index.read()) != old_index_md5:
                self.has_changes = True

        if conf.PING_GOOGLE and self.has_changes:
            try:
                sitemap_url = reverse('static_sitemaps_index')
            except NoReverseMatch:
                sitemap_url = "%ssitemap.xml" % baseurl

            self.out('Pinging google...', 2)
            ping_google(sitemap_url)
コード例 #3
0
    def __init__(self, verbosity, root_dir=None, base_url=None, language=None):
        self.verbosity = verbosity
        self.has_changes = False
        self.base_url = conf.get_url() if base_url is None else base_url
        self.root_dir = conf.ROOT_DIR if root_dir is None else root_dir
        self.language = conf.LANGUAGE if language is None else language
        try:
            self.storage = _lazy_load(
                conf.STORAGE_CLASS)(location=self.root_dir)
        except TypeError:
            self.storage = _lazy_load(conf.STORAGE_CLASS)()

        self.sitemaps = _lazy_load(conf.ROOT_SITEMAP)

        if not isinstance(self.sitemaps, dict):
            self.sitemaps = dict(enumerate(self.sitemaps))
コード例 #4
0
 def __init__(self, verbosity):
     SitemapGenerator.__init__(self, verbosity)
     self.baseurl = self.normalize_url(conf.get_url())
コード例 #5
0
 def __init__(self, verbosity):
     SitemapGenerator.__init__(self, verbosity)
     self.baseurl = self.normalize_url(conf.get_url())