Skip to content

Commit

Permalink
fix: check frontmatter generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Destructive committed Jul 10, 2022
1 parent 3395d25 commit 32400fc
Show file tree
Hide file tree
Showing 14 changed files with 490 additions and 272 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
keys.txt
config.txt
temp.json
**/crossout/
**/__pycache__/
38 changes: 0 additions & 38 deletions pyscript/app.py

This file was deleted.

File renamed without changes.
51 changes: 51 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import sys
import frontmatter
from dev import devto
from codenewbie import codenewbie
from hashnode import hashnode
import json

def get_default_or_input(dictionary, keys):
for key in keys:
if key in dictionary.keys():
return dictionary[key]
return input(f"Enter the {keys[0]} for post: ")
file_markdown = sys.argv[1]

post = frontmatter.load(file_markdown)

with open("config.json", "r") as out:
config = json.load(out)

blog_link = config["blog_link"]

article = {}
article["title"] = get_default_or_input(post, ["title"])
article["description"] = get_default_or_input(post, ["subtitle", "description"])
slug = get_default_or_input(post, ["slug", "canonical_url"])
image_url = get_default_or_input(post, ["image_url"])
canonical_url = blog_link + str(slug)
article["canonical_url"] = canonical_url
article["cover_image"] = image_url
article["tags"] = get_default_or_input(post, ["tags"])
# article['date']=post['date']
status = get_default_or_input(post, ["status", "published"])
if status == "published":
article["published"] = "true"
else:
article["published"] = "false"
article["body_markdown"] = post.content
if "series" in post:
article["series"] = post["series"]

print(f"1. dev.to \n2. hashnode.com\n3. codenewbie\n4. medium.com\n")
opt = input("Where you would like to post? (1/2/3/4) : ")

if opt == "1":
devto(article)
elif opt == "2":
hashnode(article)
elif opt == "3":
codenewbie(article)
else:
print("Invalid Option")
File renamed without changes.
4 changes: 4 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"blog_link": "https://www.meetgor.com/",
"output_folder": "crossout"
}
111 changes: 0 additions & 111 deletions src/crosspost.sh

This file was deleted.

33 changes: 31 additions & 2 deletions pyscript/dev.py → src/dev.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
import frontmatter
import requests
import json

import sys
from pathlib import Path

def devto(article):

with open("keys.txt", "r") as file:
keys = file.readlines()

post = {}

with open("config.json", "r") as out:
config = json.load(out)

output_folder = config["output_folder"]

output = Path(output_folder)
output.mkdir(parents=True, exist_ok=True)

dev_frontmatter = "---\n"
post = {}
for key in article:
post[key] = article[key]
if key == "body_markdown":
dev_frontmatter += f"---\n\n{post[key]}"
else:
if post[key]:
if not key == "published":
dev_frontmatter += f"{key}: \"{post[key]}\"\n"
else:
dev_frontmatter += f"{key}: {post[key]}\n"

with open(sys.argv[1], "w") as f:
f.write(dev_frontmatter)

filename = post['title'].replace(" ", "_").lower()
output_file = output / f"{filename}_dev_post.md"

with open(output_file, "w") as file:
file.write(dev_frontmatter)


dev_keys = keys[0]
dev_keys = dev_keys.split("dev.to:")[1].strip()
Expand Down
File renamed without changes.
21 changes: 0 additions & 21 deletions src/lib/codenewbie.sh

This file was deleted.

19 changes: 0 additions & 19 deletions src/lib/devto.sh

This file was deleted.

37 changes: 0 additions & 37 deletions src/lib/hashnode.sh

This file was deleted.

44 changes: 0 additions & 44 deletions src/lib/medium.sh

This file was deleted.

Loading

0 comments on commit 32400fc

Please sign in to comment.