Beispiel #1
0
 def process_src_file(self, in_path, relative_path, dir_metadata):
     out_path = os.path.join(self._out_dir, relative_path)
     relative_url = relative_path.replace(os.sep, '/')
     generator = get_generator(in_path)
     if generator is not None:
         out_path = '%s.html' % os.path.splitext(out_path)[0]
         relative_url = '%s.html' % os.path.splitext(relative_url)[0]
     if self._hide_index_html:
         relative_url = hide_index_html_from(relative_url)
     if not relative_url or relative_url[0] != '/':
         relative_url = '/%s' % relative_url
     if self.sitemap:
         url = self._base_url + relative_url
         self.sitemap.add(in_path, url, 'monthly', 0.5)
     if not self.should_overwrite(out_path, in_path):
         self.logger.debug('Not overwriting "%s", it seems up to date.',
                           out_path)
         return
     self._changed = True
     if generator is None:
         self.logger.info('Could not find any generator for "%s", '
                          'copying it as is.', in_path)
         if not self._do_nothing:
             shutil.copy2(in_path, out_path)
         return 1
     self.logger.info('Processing "%s" (writing in "%s").',
                      in_path, out_path)
     metadata = deepcopy(dir_metadata)
     file_metadata, body = generator.generate(in_path)
     metadata.update(file_metadata)
     metadata.update(path=relative_url)
     template_path = os.path.join(self._template_dir, self._template)
     renderer = get_renderer(template_path, self.translate)
     bindings = {'body': body,
                 'md': metadata,
                 'assets': '/assets'}
     html_output = renderer.render(**bindings)
     if not self._do_nothing:
         with open(out_path, 'wb+') as out:
             out.write(html_output.encode(ENCODING))