Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for meta description (#72)
- Loading branch information
Showing
12 changed files
with
138 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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