Last active
July 31, 2025 17:53
-
-
Save dedunumax/6facdd0258c3d939b3f64a2bd698fd3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import sys | |
| import glob | |
| if len(sys.argv) > 1: | |
| path = sys.argv[1] | |
| else: | |
| path = './' | |
| md_files = glob.glob(f"{path}/*.md") | |
| md_files = sorted(md_files) | |
| for md_file in md_files: | |
| with open(md_file, 'r') as file: | |
| title="" | |
| image="" | |
| date="" | |
| tags=[] | |
| for line in file: | |
| if line.startswith("title:"): | |
| title = line.replace("title: ", "title:").replace("title:","").replace("\"","").replace("'","").strip().replace("\n", "") | |
| if line.startswith("featured_image:"): | |
| image = line.replace("featured_image: ", "featured_image:").replace("featured_image:","").replace("\"","").replace("'","").strip().replace("\n", "") | |
| if line.startswith("- "): | |
| tags.append(line.replace("- ","").replace("\"","").replace("'","").strip().replace("\n", "")) | |
| if line.startswith("date:"): | |
| date = line.replace("date: ", "date:").replace("date:","").replace("\"","").replace("'","")[:10] | |
| if title == "": | |
| print(f"# ERROR: title - {md_file}") | |
| if image == "": | |
| print(f"# ERROR: image - {md_file}") | |
| if date == "": | |
| print(f"# ERROR: date - {md_file}") | |
| if tags == []: | |
| print(f"# ERROR: tags - {md_file}") | |
| tag_string = "" | |
| for tag in tags: | |
| tag_string = tag_string + tag + "," | |
| tag_string = tag_string[:-1] | |
| command = f"""wp post create --post_author=<User Name> --post_date='{date} 00:00:00' --post_content='<!-- wp:image {{"className":"wp-block-image size-large"}} --><figure class="wp-block-image size-large"><img src="https://cdn.dedunu.info/travel/images/{image}" alt=""/></figure><!-- /wp:image -->' --comment_status='closed' --post_title='{title}' --post_category='travel' --tags_input='{tag_string}' --post_status='publish' | |
| """ | |
| print(f"echo '{md_file}'") | |
| print(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment