Publish_Dev_To_Source.Py
None
!! function
should_join function
should_join source
def should_join(line): if line == "": return False if line is None: return False if line[0].isalpha(): return True if line[0].startswith("["): return True if line[0].startswith("!"): return True return False
!! function
join_lines function
join_lines source
def join_lines(article): lines = article.split("\n") line_number = 0 while line_number + 1 < len(lines): line = lines[line_number] nextline = lines[line_number + 1] if should_join(line) and should_join(nextline): lines[line_number] = f"{line} {nextline}" lines.pop(line_number + 1) else: line_number += 1 return "\n".join(lines)
!! class
PublishDevToSourcePost class
PublishDevToSourcePost source
class PublishDevToSourcePost(BaseModel): markata: Any = Field(None, exclude=True) canonical_url: Optional[str] = None
!! function
post_model function
post_model source
def post_model(markata: "Markata") -> None: markata.post_models.append(PublishDevToSourcePost)
!! function
post_render function
post_render source
def post_render(markata: "Markata") -> None: for post in markata.iter_articles(description="saving source documents"): article = frontmatter.Post( post.content, **{k: v for k, v in post.metadata.items() if k in DEV_TO_FRONTMATTER}, ) article.content = join_lines(article.content) article.content = join_lines(article.content) if "canonical_url" not in article: article["canonical_url"] = f"{markata.config.url}/{post.slug}/" if "published" not in article: article["published"] = True if "cover_image" not in article: article["cover_image"] = f"{markata.config.images_url}/{post.slug}.png" post.dev_to = article
!! function
save function
save source
def save(markata: "Markata") -> None: output_dir = Path(str(markata.config.output_dir)) with markata.console.status("Saving source documents...") as status: for post in markata.iter_articles(description="saving source documents"): status.update(f"Saving {post['slug']}...") with open(output_dir / Path(post["slug"]) / "dev.md", "w+") as f: f.write(frontmatter.dumps(post.dev_to))