Exemple #1
0
async def generate(site: Site) -> None:
    logger = logging.getLogger()
    await site.assets.copytree(join('public', 'static'),
                               site.configuration.www_directory_path)
    await site.renderer.render_tree(site.configuration.www_directory_path)
    await site.dispatcher.dispatch(PostStaticGenerator, 'post_static_generate')()
    for locale, locale_configuration in site.configuration.locales.items():
        async with site.with_locale(locale) as site:
            if site.configuration.multilingual:
                www_directory_path = join(
                    site.configuration.www_directory_path, locale_configuration.alias)
            else:
                www_directory_path = site.configuration.www_directory_path

            await site.assets.copytree(join('public', 'localized'), www_directory_path)
            await site.renderer.render_tree(www_directory_path)

            locale_label = Locale.parse(locale, '-').get_display_name()
            await _generate_entity_type(www_directory_path, site.ancestry.files.values(
            ), 'file', site, locale, site.jinja2_environment)
            logger.info('Generated pages for %d files in %s.' %
                        (len(site.ancestry.files), locale_label))
            await _generate_entity_type(www_directory_path, site.ancestry.people.values(
            ), 'person', site, locale, site.jinja2_environment)
            logger.info('Generated pages for %d people in %s.' %
                        (len(site.ancestry.people), locale_label))
            await _generate_entity_type(www_directory_path, site.ancestry.places.values(
            ), 'place', site, locale, site.jinja2_environment)
            logger.info('Generated pages for %d places in %s.' %
                        (len(site.ancestry.places), locale_label))
            await _generate_entity_type(www_directory_path, site.ancestry.events.values(
            ), 'event', site, locale, site.jinja2_environment)
            logger.info('Generated pages for %d events in %s.' %
                        (len(site.ancestry.events), locale_label))
            await _generate_entity_type(www_directory_path, site.ancestry.citations.values(
            ), 'citation', site, locale, site.jinja2_environment)
            logger.info('Generated pages for %d citations in %s.' %
                        (len(site.ancestry.citations), locale_label))
            await _generate_entity_type(www_directory_path, site.ancestry.sources.values(
            ), 'source', site, locale, site.jinja2_environment)
            logger.info('Generated pages for %d sources in %s.' %
                        (len(site.ancestry.sources), locale_label))
            _generate_entity_type_list_json(www_directory_path, site.ancestry.notes.values(), 'note', site)
            for note in site.ancestry.notes.values():
                _generate_entity_json(www_directory_path, note, 'note', site, locale)
            logger.info('Generated pages for %d notes in %s.' % (len(site.ancestry.notes), locale_label))
            _generate_openapi(www_directory_path, site)
            logger.info('Generated OpenAPI documentation in %s.', locale_label)
    chmod(site.configuration.www_directory_path, 0o755)
    for directory_path, subdirectory_names, file_names in os.walk(site.configuration.www_directory_path):
        for subdirectory_name in subdirectory_names:
            chmod(join(directory_path, subdirectory_name), 0o755)
        for file_name in file_names:
            chmod(join(directory_path, file_name), 0o644)
    await site.dispatcher.dispatch(PostGenerator, 'post_generate')()
Exemple #2
0
 async def populate_link(self, link: Link, site: Site, entry_language: str, entry: Optional[Entry] = None) -> None:
     if link.url.startswith('http:'):
         link.url = 'https:' + link.url[5:]
     if link.media_type is None:
         link.media_type = 'text/html'
     if link.relationship is None:
         link.relationship = 'external'
     if link.locale is None:
         link.locale = entry_language
     if link.description is None:
         # There are valid reasons for links in locales that aren't supported.
         with suppress(ValueError):
             async with site.with_locale(link.locale):
                 link.description = _('Read more on Wikipedia.')
     if entry is not None and link.label is None:
         link.label = entry.title