mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-07-04 15:41:00 +00:00

* First pass at syncing Haystack API with Readme * Reapply changes * Regularize slugs * Regularize slugs * Regularize slugs * Set category id and regen * Trigger workflow * Delete old md files * Test sync * Undo test string * Incorporate reviewer feedback * Test on the fly API generation and sync * Test on the fly API generation and sync * Test on the fly API generation and sync * Test on the fly API generation and sync * Test on the fly API generation and sync * Change name of pydoc-markdown scripts * Test on the fly API generation and sync * Remove version tag * Test version tag * Test version tag * Test version tag * Revert test docstring * Revert md file changes * Revert md file changes * Revert script naming * Test on the fly generation and sync * Adjust for on the fly generation and sync * Revert test string * Remove old documentation workflow * Set workflow to work on main * Change readme version name
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import sys
|
|
import io
|
|
import dataclasses
|
|
import docspec
|
|
import typing as t
|
|
from pathlib import Path
|
|
from pydoc_markdown.interfaces import Context, Renderer
|
|
from pydoc_markdown.contrib.renderers.markdown import MarkdownRenderer
|
|
|
|
|
|
README_FRONTMATTER = """---
|
|
title: {title}
|
|
excerpt: {excerpt}
|
|
category: {category}
|
|
slug: {slug}
|
|
order: {order}
|
|
hidden: false
|
|
---
|
|
|
|
"""
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class ReadmeRenderer(Renderer):
|
|
"""
|
|
This custom Renderer is heavily based on the `MarkdownRenderer`,
|
|
it just prepends a front matter so that the output can be published
|
|
directly to readme.io.
|
|
"""
|
|
|
|
# These settings will be used in the front matter output
|
|
title: str
|
|
category: str
|
|
excerpt: str
|
|
slug: str
|
|
order: int
|
|
# This exposes a special `markdown` settings value that can be used to pass
|
|
# parameters to the underlying `MarkdownRenderer`
|
|
markdown: MarkdownRenderer = dataclasses.field(default_factory=MarkdownRenderer)
|
|
|
|
def init(self, context: Context) -> None:
|
|
self.markdown.init(context)
|
|
|
|
def render(self, modules: t.List[docspec.Module]) -> None:
|
|
if self.markdown.filename is None:
|
|
sys.stdout.write(self._frontmatter())
|
|
self.markdown.render_to_stream(modules, sys.stdout)
|
|
else:
|
|
with io.open(self.markdown.filename, "w", encoding=self.markdown.encoding) as fp:
|
|
fp.write(self._frontmatter())
|
|
self.markdown.render_to_stream(modules, t.cast(t.TextIO, fp))
|
|
|
|
def _frontmatter(self) -> str:
|
|
return README_FRONTMATTER.format(
|
|
title=self.title, category=self.category, excerpt=self.excerpt, slug=self.slug, order=self.order
|
|
)
|