Skip to content

Commit 2693a4d

Browse files
authored
DOP-3438: Remove devhub data paths (#437)
* DOP-3438: Remove devhub data paths * Remove devhub from rstspec.toml and test_data
1 parent dc3417a commit 2693a4d

File tree

13 files changed

+3
-583
lines changed

13 files changed

+3
-583
lines changed

snooty/parser.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
from .n import FileId, SerializableType, TocTreeDirectiveEntry
7272
from .openapi import OpenAPI
7373
from .page import Page, PendingTask
74-
from .postprocess import DevhubPostprocessor, Postprocessor, PostprocessorResult
74+
from .postprocess import Postprocessor, PostprocessorResult
7575
from .target_database import ProjectInterface, TargetDatabase
7676
from .types import BuildIdentifierSet, ParsedBannerConfig, ProjectConfig, StaticAsset
7777
from .util import RST_EXTENSIONS
@@ -940,7 +940,7 @@ def _locate_text(text: str) -> int:
940940
if "date" in node:
941941
doc.options["date"] = node["date"]
942942

943-
elif key in {"devhub:author", ":og", ":twitter"}:
943+
elif key in {":og", ":twitter"}:
944944
# Grab image from options array and save as static asset
945945
image_argument = options.get("image")
946946

@@ -1554,9 +1554,7 @@ def __init__(
15541554
self.prefix = [self.config.name, username, branch]
15551555

15561556
self.pages = PageDatabase(
1557-
lambda: DevhubPostprocessor(self.config, self.targets.copy_clean_slate())
1558-
if self.config.default_domain == "devhub"
1559-
else Postprocessor(self.config, self.targets.copy_clean_slate())
1557+
lambda: Postprocessor(self.config, self.targets.copy_clean_slate())
15601558
)
15611559

15621560
self.asset_dg: "networkx.DiGraph[FileId]" = networkx.DiGraph()

snooty/postprocess.py

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,134 +1912,3 @@ def clean_slug(slug: str) -> str:
19121912
return root
19131913

19141914
return slug
1915-
1916-
1917-
class DevhubHandler(Handler):
1918-
# TODO: Identify directives that should be exposed in the rstspec.toml to avoid hardcoding
1919-
# These directives are represented as list nodes; they will return a list of strings
1920-
LIST_FIELDS = {"devhub:products", "devhub:tags", ":languages"}
1921-
# These directives have their content represented as children; they will return a list of nodes
1922-
BLOCK_FIELDS = {"devhub:meta-description"}
1923-
# These directives have their content represented as an argument; they will return a string
1924-
ARG_FIELDS = {"devhub:level", "devhub:type", ":atf-image"}
1925-
# These directives have their content represented as children, along with a series of options;
1926-
# they will return a dictionary with all options represented, and with the content represented as a list of nodes whose key is `children`.
1927-
OPTION_BLOCK_FIELDS = {":og", ":twitter"}
1928-
1929-
def enter_page(self, fileid_stack: FileIdStack, page: Page) -> None:
1930-
"""To be called at the start of each page: reset the query field dictionary"""
1931-
self.query_fields: Dict[str, Any] = {}
1932-
1933-
def exit_page(self, fileid_stack: FileIdStack, page: Page) -> None:
1934-
"""To be called at the end of each page: append the query field dictionary to the
1935-
top level of the page's class instance.
1936-
"""
1937-
# Save page title to query_fields, if it exists
1938-
slug = clean_slug(fileid_stack.current.as_posix())
1939-
self.query_fields["slug"] = f"/{slug}" if slug != "index" else "/"
1940-
title = self.context[HeadingHandler].get_title(slug)
1941-
if title is not None:
1942-
self.query_fields["title"] = [node.serialize() for node in title]
1943-
1944-
page.query_fields = self.query_fields
1945-
1946-
def enter_node(self, fileid_stack: FileIdStack, node: n.Node) -> None:
1947-
"""Extract fields from a page's AST and expose them as a queryable nested document in the page document."""
1948-
if not isinstance(node, n.Directive):
1949-
return
1950-
1951-
key = f"{node.domain}:{node.name}"
1952-
1953-
if key == "devhub:author":
1954-
# Create a dict unifying the node's options and children
1955-
author_obj: Dict[str, SerializableType] = {}
1956-
author_obj.update(node.options)
1957-
author_obj["children"] = [child.serialize() for child in node.children]
1958-
1959-
self.query_fields.setdefault("author", []).append(author_obj)
1960-
elif key == "devhub:related":
1961-
# Save list of nodes (likely :doc: roles)
1962-
self.query_fields[node.name] = []
1963-
if len(node.children) > 0:
1964-
first_child = node.children[0]
1965-
assert isinstance(first_child, n.Parent)
1966-
for item in first_child.children:
1967-
paragraph = item.children[0]
1968-
self.query_fields[node.name].append(
1969-
paragraph.children[0].serialize()
1970-
)
1971-
elif key in {":pubdate", ":updated-date"}:
1972-
date = node.options.get("date")
1973-
if date:
1974-
self.query_fields[node.name] = date
1975-
elif key in self.OPTION_BLOCK_FIELDS:
1976-
# Create a dict unifying the node's options and children
1977-
node_obj: Dict[str, SerializableType] = {}
1978-
node_obj.update(node.options)
1979-
node_obj["children"] = [child.serialize() for child in node.children]
1980-
1981-
self.query_fields[node.name] = node_obj
1982-
elif key in self.ARG_FIELDS:
1983-
if len(node.argument) > 0:
1984-
self.query_fields[node.name] = node.argument[0].value
1985-
elif key in self.BLOCK_FIELDS:
1986-
self.query_fields[node.name] = [
1987-
child.serialize() for child in node.children
1988-
]
1989-
elif key in self.LIST_FIELDS:
1990-
self.query_fields[node.name] = []
1991-
if len(node.children) > 0:
1992-
first_child = node.children[0]
1993-
assert isinstance(first_child, n.Parent)
1994-
list_items = first_child.children
1995-
assert isinstance(list_items, List)
1996-
for item in list_items:
1997-
text_candidate = get_deepest(item)
1998-
assert isinstance(text_candidate, n.Text)
1999-
self.query_fields[node.name].append(text_candidate.value)
2000-
2001-
2002-
class DevhubPostprocessor(Postprocessor):
2003-
"""Postprocess operation to be run if a project's default_domain is equal to 'devhub'"""
2004-
2005-
PASSES: Sequence[Sequence[Type[Handler]]] = [
2006-
[IncludeHandler],
2007-
[SubstitutionHandler],
2008-
[
2009-
HeadingHandler,
2010-
AddTitlesToLabelTargetsHandler,
2011-
ProgramOptionHandler,
2012-
TabsSelectorHandler,
2013-
ContentsHandler,
2014-
BannerHandler,
2015-
GuidesHandler,
2016-
OpenAPIHandler,
2017-
],
2018-
[TargetHandler, IAHandler, NamedReferenceHandlerPass1],
2019-
[RefsHandler, NamedReferenceHandlerPass2, DevhubHandler],
2020-
]
2021-
2022-
def finalize(self, context: Context, metadata: n.SerializedNode) -> None:
2023-
def clean_and_validate_page_group_slug(slug: str) -> Optional[str]:
2024-
"""Clean a slug and validate that it is a known page. If it is not, return None."""
2025-
cleaned = clean_slug(slug)
2026-
if cleaned not in context[HeadingHandler]:
2027-
# XXX: Because reporting errors in config.toml properly is dodgy right now, just
2028-
# log to stderr.
2029-
logger.error(f"Cannot find slug '{cleaned}'")
2030-
return None
2031-
2032-
return cleaned
2033-
2034-
# Normalize all page group slugs
2035-
page_groups = {
2036-
title: [
2037-
slug
2038-
for slug in (clean_and_validate_page_group_slug(slug) for slug in slugs)
2039-
if slug
2040-
]
2041-
for title, slugs in self.project_config.page_groups.items()
2042-
}
2043-
2044-
if page_groups:
2045-
metadata.update({"pageGroups": page_groups})

snooty/rstspec.toml

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ card_layout = ["default", "carousel"]
1111
card_style = ["default", "compact", "extra-compact"]
1212
card_type = ["small", "large"]
1313
charts_theme = ["light", "dark"]
14-
devhub_type = ["article", "quickstart", "how-to", "video", "live"]
1514
guide_categories = ["Getting Started"]
1615
mws_version = ["3.4", "3.6", "4.0", "4.2", "4.4", "5.0", "latest"]
1716
output_format = ["html"]
@@ -561,139 +560,6 @@ help = """A list of languages that this guide supports."""
561560
# """
562561
content_type = "list"
563562

564-
###### DevHub
565-
[directive._devhub-base]
566-
required_context = "devhub"
567-
568-
[directive._devhub-inline]
569-
inherit = "_devhub-base"
570-
argument_type = "string"
571-
572-
[directive._devhub-block]
573-
inherit = "_devhub-base"
574-
content_type = "block"
575-
576-
[directive."devhub:meta-description"]
577-
help = "Short and simple explanation of what the page is about. Try to include a target keyword and call to action. 125–155 Characters."
578-
inherit = "_devhub-block"
579-
example = """.. meta-description::
580-
581-
${0:Short and simple explanation of what the page is about. Try to
582-
include a target keyword and call to action. 125–155 Characters.}
583-
"""
584-
585-
[directive."devhub:author"]
586-
help = "Author profile for the byline."
587-
example = """.. author::
588-
:name: ${1:Eliot Horowitz}
589-
:image: ${2:/path/to/image.jpg}
590-
:location: ${3:New York, NY}
591-
:company: ${4:MongoDB Inc.}
592-
:title: ${5:Co-founder}
593-
:website: ${6:http://www.example.com}
594-
:twitter: ${7:https://twitter.com/eliothorowitz}
595-
:github: ${8:https://github.com/erh}
596-
:linkedin: ${9:https://www.linkedin.com/in/eliothorowitz/}
597-
598-
${0:Author bio goes here.}
599-
"""
600-
inherit = "_devhub-block"
601-
options.name = "string"
602-
options.image = ["path", "uri"]
603-
options.location = "string"
604-
options.company = "string"
605-
options.title = "string"
606-
options.website = "uri"
607-
options.twitter = "uri"
608-
options.github = "uri"
609-
options.linkedin = "uri"
610-
611-
612-
[directive."devhub:type"]
613-
help = "Specify the type of document"
614-
inherit = "_devhub-inline"
615-
argument_type = "devhub_type"
616-
example = """.. type:: ${1|article,quickstart,how-to,video,live|}
617-
"""
618-
619-
[directive."devhub:level"]
620-
help = "Specify the experience level of the audience: beginner, intermediate, or advanced"
621-
inherit = "_devhub-inline"
622-
argument_type = "user_level"
623-
example = """.. level:: ${1|beginner,intermediate,advanced|}
624-
"""
625-
626-
[directive."devhub:tags"]
627-
help = "User-specified tags."
628-
example = """.. tags::
629-
630-
* ${0:first tag
631-
* second tag
632-
* third tag}
633-
"""
634-
inherit = "_devhub-block"
635-
content_type = "list"
636-
637-
[directive."devhub:products"]
638-
help = "MongoDB products discussed in the article"
639-
example = """.. products::
640-
641-
* ${0:Realm
642-
* MongoDB Atlas}
643-
"""
644-
inherit = "_devhub-block"
645-
content_type = "list"
646-
647-
[directive."devhub:callout"]
648-
help = "Call out a specific University course, blog post, event, etc."
649-
inherit = "_devhub-block"
650-
example = """.. callout::
651-
${0:Call out specific content, such as an event, University course, etc.}
652-
"""
653-
654-
[directive."devhub:introduction"]
655-
help = "Capture the reader's attention, offer the reason for the article's existence, and explain how the content will address the problem. Use the target keyword in the first 100 words."
656-
inherit = "_devhub-block"
657-
example = """.. introduction::
658-
659-
${0:Capture the reader's attention, offer the reason for the article's existence,
660-
and explain how the content will address the problem.
661-
Use the target keyword in the first 100 words.}
662-
"""
663-
664-
[directive."devhub:prerequisites"]
665-
help = "If your content has prerequisites, describe them here."
666-
inherit = "_devhub-block"
667-
example = """.. prerequisites::
668-
669-
${0:If your content has prerequisites, describe them here}
670-
"""
671-
672-
[directive."devhub:content"]
673-
help = "Body of the article. Use headers, links, lists, etc."
674-
inherit = "_devhub-block"
675-
example = """.. content::
676-
677-
${0:Article content}
678-
"""
679-
680-
[directive."devhub:summary"]
681-
help = "Summarize or conclude the article. Include a relevant call to action."
682-
inherit = "_devhub-block"
683-
example = """.. summary::
684-
685-
${0:Summarize or conclude the article. Include a relevant call to action.}
686-
"""
687-
688-
[directive."devhub:related"]
689-
help = "List of related articles."
690-
inherit = "_devhub-block"
691-
content_type = "list"
692-
example = """.. related::
693-
694-
* ${0: /path-to-first-related-article
695-
* https://url-of-related-article}
696-
"""
697563

698564
##### Guides (LEGACY - do not deprecate until removed in dependent docs repos)
699565
[directive.hlist]

0 commit comments

Comments
 (0)