8000 Fix first_image not resolving correctly in subdirectories (#61) · sphinx-doc/sphinxext-opengraph@ada5be9 · GitHub
[go: up one dir, main page]

Skip to content

Commit ada5be9

Browse files
ItayZivTheTripleV
andauthored
Fix first_image not resolving correctly in subdirectories (#61)
Co-authored-by: TheTripleV <vasistavovveti@gmail.com>
1 parent d99815b commit ada5be9

File tree

29 files changed

+94
-51
lines changed
  • test-local-image
  • test-nested-lists
  • test-overrides-complex
  • test-overrides-simple
  • test-quotation-marks
  • test-simple
  • test-sitename
  • test-skip-admonitions
  • test-skip-code-block
  • test-skip-comments
  • test-skip-raw
  • test-skip-title
  • test-type
  • 29 files changed

    +94
    -51
    lines changed

    sphinxext/opengraph/__init__.py

    Lines changed: 11 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -130,12 +130,19 @@ def get_tags(
    130130

    131131
    if image_url:
    132132
    # temporarily disable relative image paths with field lists
    133-
    if image_url and "og:image" not in fields:
    133+
    if "og:image" not in fields:
    134134
    image_url_parsed = urlparse(image_url)
    135135
    if not image_url_parsed.scheme:
    136-
    # Relative image path detected. Make absolute.
    137-
    image_url = urljoin(config["ogp_site_url"], image_url_parsed.path)
    138-
    tags["og:image"] = image_url
    136+
    # Relative image path detected, relative to the source. Make absolute.
    137+
    if config["ogp_image"]:
    138+
    # ogp_image is defined as being relative to the site root.
    139+
    # This workaround is to keep that functionality from breaking.
    140+
    root = config["ogp_site_url"]
    141+
    else:
    142+
    root = page_url
    143+
    144+
    image_url = urljoin(root, image_url_parsed.path)
    145+
    tags["og:image"] = image_url
    139146

    140147
    # Add image alt text (either provided by config or from site_name)
    141148
    if isinstance(ogp_image_alt, str):

    tests/roots/test-arbitrary-tags/conf.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -5,4 +5,4 @@
    55

    66
    html_theme = "basic"
    77

    8-
    ogp_site_url = "http://example.org/"
    8+
    ogp_site_url = "http://example.org/en/latest/"
    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,4 +1,4 @@
    1-
    :og:video: http://example.org/video.mp4
    1+
    :og:video: http://example.org/en/latest/video.mp4
    22
    :og:video:type: video/mp4
    33

    44
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse at lorem ornare, fringilla massa nec, venenatis mi. Donec erat sapien, tincidunt nec rhoncus nec, scelerisque id diam. Orci varius natoque penatibus et magnis dis parturient mauris.

    tests/roots/test-custom-tags/conf.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -5,7 +5,7 @@
    55

    66
    html_theme = "basic"
    77

    8-
    ogp_site_url = "http://example.org/"
    8+
    ogp_site_url = "http://example.org/en/latest/"
    99

    1010
    ogp_custom_meta_tags = [
    1111
    '<meta property="og:ignore_canonical" content="true" />',

    tests/roots/test-description-length/conf.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -5,5 +5,5 @@
    55

    66
    html_theme = "basic"
    77

    8-
    ogp_site_url = "http://example.org/"
    8+
    ogp_site_url = "http://example.org/en/latest/"
    99
    ogp_description_length = 50

    tests/roots/test-double-spacing/conf.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -5,4 +5,4 @@
    55

    66
    html_theme = "basic"
    77

    8-
    ogp_site_url = "http://example.org/"
    8+
    ogp_site_url = "http://example.org/en/latest/"

    tests/roots/test-first-image-no-image/conf.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -6,7 +6,7 @@
    66
    html_theme = "basic"
    77

    88
    ogp_site_name = "Example's Docs!"
    9-
    ogp_site_url = "http://example.org/"
    10-
    ogp_image = "http://example.org/image33.png"
    9+
    ogp_site_url = "http://example.org/en/latest/"
    10+
    ogp_image = "http://example.org/en/latest/image33.png"
    1111
    ogp_image_alt = "TEST"
    1212
    ogp_use_first_image = True

    tests/roots/test-first-image/conf.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -6,7 +6,7 @@
    66
    html_theme = "basic"
    77

    88
    ogp_site_name = "Example's Docs!"
    9-
    ogp_site_url = "http://example.org/"
    10-
    ogp_image = "http://example.org/image33.png"
    9+
    ogp_site_url = "http://example.org/en/latest/"
    10+
    ogp_image = "http://example.org/en/latest/image33.png"
    1111
    ogp_image_alt = "TEST"
    1212
    ogp_use_first_image = True
    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,2 +1,2 @@
    1-
    .. image:: http://example.org/image2.png
    1+
    .. image:: http://example.org/en/latest/image2.png
    22
    :alt: Test image alt text

    tests/roots/test-image-rel-paths/conf.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -6,5 +6,5 @@
    66
    html_theme = "basic"
    77

    88
    ogp_site_name = "Example's Docs!"
    9-
    ogp_site_url = "http://example.org/"
    9+
    ogp_site_url = "http://example.org/en/latest/"
    1010
    ogp_use_first_image = True

    0 commit comments

    Comments
     (0)
    0