Example #1
0
    def visit_reference(self, node):
        def get_link(docname):
            result = None
            app = self.builder.app
            if hasattr(app, 'first_permalinks'):
                result = app.first_permalinks.get(docname)
            return result

        ru = node.get('refuri')
        local = False
        if not self.toctree and node.get('internal') and not node.get('refid'):
            an = node.get('anchorname')
            if ru == '#' or an and an == ru:
                local = True

        # Fix up a bare '#' fragment to be a more sensible value.
        fragment_fixup = (
            (ru == '#') or  # local TOC node
            ('current' in node.get('classes')))  # global TOC node
        if fragment_fixup:
            link = get_link(self.builder.current_docname)
            if link:
                node['refuri'] = '#%s' % link
        if local:
            node.attributes['classes'].append('lvl-%d' % self.li_level)
        if (self.toctree and ru is not None and '#' not in ru
                and ru.endswith('.html')):
            name = ru.rsplit('.', 1)[0]
            while name.startswith('../'):
                name = name[3:]
            link = get_link(name)
            if link:
                node['refuri'] = '%s#%s' % (ru, link)
                logger.debug('visit_reference: %s -> %s', ru, node['refuri'])
        super(Translator, self).visit_reference(node)
Example #2
0
def on_build_finished(app, exception):
    if app.sitemap_urls:
        create_sitemap(app)
    create_app_data(app)

    # remove unused files.
    outdir = app.builder.outdir
    unused = (
        ('_static', 'jquery.js'),
        ('_static', 'jquery-3.2.1.js'),
        ('_static', 'underscore.js'),
        ('_static', 'underscore-1.3.1.js'),
        ('_static', 'ajax-loader.gif'),
        ('_static', 'comment.png'),
        ('_static', 'comment-bright.png'),
        ('_static', 'comment-close.png'),
        #('_static', 'file.png'),
        ('_static', 'up.png'),
        ('_static', 'up-pressed.png'),
        ('_static', 'down.png'),
        ('_static', 'down-pressed.png'),
        #('_static', 'plus.png'),
        #('_static', 'minus.png'),
        ('_static', 'basic.css'),
    )
    for cp in unused:
        p = path.join(outdir, *cp)
        if path.isfile(p):
            remove(p)
        elif path.isdir(p):
            rmtree(p)
    logger.debug('Build finished.')
Example #3
0
def on_doctree_read(app, doctree):
    # Ideally, the docname would also have been made available ... but it hasn't
    # been. So, we try and use hackery to find it :-(
    #
    # This is so that the first permalink information is available as early as
    # possible in the process. The build process reads all the docs, and then
    # goes through each document doing a doctree-resolve and write operation.
    # The documents early in the process won't have the permalink information
    # that the later ones do.
    #
    # OK - disabled the stack hack for now, but may have to reinstate later
    #
    use_stack_hack = False
    if use_stack_hack:
        docname = find_docname()
        if docname:
            app.first_permalinks[docname] = find_first_permalink(doctree)
        logger.debug('on_doctree_read: %s', docname)
Example #4
0
def on_page(app, pagename, templatename, context, doctree):
    options = app.config['html_theme_options']
    base_url = options.get('sitemap_url')
    fonts = options.get('google_fonts')
    if pagename == 'index':
        if fonts:
            if isinstance(fonts, basestring):
                fonts = fonts.split(',')
            elif not isinstance(fonts, list):
                raise TypeError('The "fonts" theme option must be a string or '
                                'a list')
            context['theme_google_fonts'] = '|%s' % '|'.join(fonts)
    if pagename != 'search' and base_url:
        url = urljoin(base_url, pagename + '.html')
        app.sitemap_urls.append(url)
    context['sizzle_version'] = app.sizzle_version
    context['build_date'] = datetime.date.today().strftime('%Y-%m-%d')
    if pagename != 'search':
        app_data_path = context['pathto']('search').replace(
            'search.html', 'app-data.js')
        if app_data_path != '#':
            context['app_data_path'] = app_data_path
    logger.debug('on_page: %s', pagename)
Example #5
0
 def __init__(self, *args, **kwargs):
     super(Translator, self).__init__(*args, **kwargs)
     self.li_level = 0
     toctree = False
     # Depending on Sphinx version, the document can be in different
     # positions in the argument list! Honestly ... just in case it moves
     # again, we look in the whole arg list and stop when a document is
     # found.
     for arg in args:
         if isinstance(arg, document):
             toctree = arg.children[0].get('toctree', False)
             break
     self.toctree = toctree
     if toctree:
         logger.debug('translate toctree: %s', self.builder.current_docname)
     # Remove limit on field names (ensures parameters are in two columns)
     self.settings.field_name_limit = 0
     self.in_glossary = self.in_field_body = False
     ctx = self.builder.globalcontext
     self.enable_tooltips = ctx.get('theme_enable_tooltips') in (True,
                                                                 'true')
     self.glossary_permalinks = ctx.get('theme_glossary_permalinks') in (
         True, 'true')
     self.debugging = False
Example #6
0
def on_doctree_resolved(app, doctree, docname):
    if docname not in app.first_permalinks:
        app.first_permalinks[docname] = find_first_permalink(doctree)
    logger.debug('on_doctree_resolved: %s', docname)