File: utils.py

package info (click to toggle)
sphinx-notfound-page 1.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 920 kB
  • sloc: python: 699; makefile: 15
file content (49 lines) | stat: -rw-r--r-- 1,696 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sphinx


def _get_css_html_link_tag(app, language, version, filename):
    if not language and not version:
        href = '/_static/{filename}'.format(filename=filename)
    else:
        href = '/{language}/{version}/_static/{filename}'.format(
            language=language,
            version=version,
            filename=filename,
        )

    if sphinx.version_info >= (7, 1):
        # it requires `?v={hash}`
        if sphinx.version_info < (7, 2):
            from sphinx.builders.html import _file_checksum
        else:
            from sphinx.builders.html._assets import _file_checksum
        filehash = _file_checksum(app.outdir / "_static", filename)
        if filehash:
            href = f"{href}?v={filehash}"

    return '<link rel="stylesheet" type="text/css" href="{href}" />'.format(href=href)


def _get_js_html_link_tag(app, language, version, filename):
    if not language and not version:
        src = '/_static/{filename}'.format(filename=filename)
    else:
        src = '/{language}/{version}/_static/{filename}'.format(
            language=language,
            version=version,
            filename=filename,
        )

    if sphinx.version_info >= (7, 1):
        # it requires `?v={hash}`
        if sphinx.version_info < (7, 2):
            from sphinx.builders.html import _file_checksum
        else:
            from sphinx.builders.html._assets import _file_checksum
        filehash = _file_checksum(app.outdir / "_static", filename)
        if filehash:
            src = f"{src}?v={filehash}"

    # #6925: html: Remove redundant type="text/javascript" from <script> elements
    return '<script src="{src}"></script>'.format(src=src)