-
-
Notifications
You must be signed in to change notification settings - Fork 30
Add support for meta description #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TheTripleV
merged 6 commits into
sphinx-doc:main
from
hugovk:no-override-manual-meta-description
Oct 26, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b827e1
Don't overwrite a page's existing manual meta description tag
hugovk de9eccc
Allow testing feature branches
hugovk 161f2b5
Don't overwrite a page's existing manual meta og:description tag
hugovk c6eccdf
Update documentation
hugovk b95a988
Default ogp_enable_meta_description to True
hugovk 8f4b966
Run on external PRs but not internal PRs
hugovk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from html.parser import HTMLParser | ||
|
||
|
||
class HTMLTextParser(HTMLParser): | ||
""" | ||
Parse HTML into text | ||
""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.meta_description = None | ||
|
||
def handle_starttag(self, tag, attrs) -> None: | ||
# For example: | ||
# attrs = [("content", "My manual description"), ("name", "description")] | ||
if ("name", "description") in attrs: | ||
self.meta_description = True | ||
for name, value in attrs: | ||
if name == "content": | ||
self.meta_description = value | ||
break | ||
|
||
|
||
def get_meta_description(meta_tags: str) -> bool: | ||
htp = HTMLTextParser() | ||
htp.feed(meta_tags) | ||
htp.close() | ||
|
||
return htp.meta_description |
10 changes: 10 additions & 0 deletions
10
tests/roots/test-meta-name-description-manual-description/conf.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extensions = ["sphinxext.opengraph"] | ||
|
||
master_doc = "index" | ||
exclude_patterns = ["_build"] | ||
|
||
html_theme = "basic" | ||
|
||
ogp_site_url = "http://example.org/en/latest/" | ||
|
||
ogp_enable_meta_description = True |
4 changes: 4 additions & 0 deletions
4
tests/roots/test-meta-name-description-manual-description/index.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.. meta:: | ||
:description: My manual description | ||
|
||
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. |
10 changes: 10 additions & 0 deletions
10
tests/roots/test-meta-name-description-manual-og-description/conf.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extensions = ["sphinxext.opengraph"] | ||
|
||
master_doc = "index" | ||
exclude_patterns = ["_build"] | ||
|
||
html_theme = "basic" | ||
|
||
ogp_site_url = "http://example.org/en/latest/" | ||
|
||
ogp_enable_meta_description = True |
3 changes: 3 additions & 0 deletions
3
tests/roots/test-meta-name-description-manual-og-description/index.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:og:description: My manual og:description | ||
|
||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extensions = ["sphinxext.opengraph"] | ||
|
||
master_doc = "index" | ||
exclude_patterns = ["_build"] | ||
|
||
html_theme = "basic" | ||
|
||
ogp_site_url = "http://example.org/en/latest/" | ||
|
||
enable_meta_description = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.