Skip to content

Commit

Permalink
change images metatag to md format
Browse files Browse the repository at this point in the history
  • Loading branch information
arash77 committed May 16, 2024
1 parent cf885ac commit 78af8ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div align="center">
👇</br>
<kbd><a href="../../new/main/?filename=posts/2024/<your-path>.md&value=---%0Amedia%3A%0A%20 - bluesky%0A%20 - mastodon%0A%20 - matrix%0A%20 - slack%0A%0Aimages%3A%0A%20 - url%3A https%3A%2F%2Fexample.com%2Fa.jpg%0A%20%20%20 alt_text%3A A%0A%20 - url%3A https%3A%2F%2Fexample.org%2Fb.png%0A%20%20%20 alt_text%3A B%0A%0Amentions%3A%0A%20 bluesky%3A%0A%20%20%20 - a.bsky.social%0A%20 mastodon%3A%0A%20%20%20 - a%0A%20 matrix%3A%0A%20%20%20 - a%3Amatrix.org%0A%0Ahashtags%3A%0A%20 bluesky%3A%0A%20%20%20 - a%0A%20%20%20 - b%0A%20 mastodon%3A%0A%20%20%20 - c%0A%20%20%20 - d%0A---%0AYour text content goes here.">Create new post</a></kbd>
<kbd><a href="../../new/main/?filename=posts/2024/<your-path>.md&value=---%0Amedia%3A%0A%20 - bluesky%0A%20 - mastodon%0A%20 - matrix%0A%20 - slack%0A%0Amentions%3A%0A%20 bluesky%3A%0A%20%20%20 - a.bsky.social%0A%20 mastodon%3A%0A%20%20%20 - a%0A%20 matrix%3A%0A%20%20%20 - a%3Amatrix.org%0A%0Ahashtags%3A%0A%20 bluesky%3A%0A%20%20%20 - a%0A%20%20%20 - b%0A%20 mastodon%3A%0A%20%20%20 - c%0A%20%20%20 - d%0A---%0AYour text content goes here.%0A%0A![A](https%3A%2F%2Fexample.com%2Fa.jpg)%0A![B](https%3A%2F%2Fexample.org%2Fb.png)">Create new post</a></kbd>
</div>

## How to Create a Post
Expand All @@ -23,12 +23,6 @@ media:
- matrix
- slack

images:
- url: https://example.com/a.jpg
alt_text: A
- url: https://example.org/b.png
alt_text: B

mentions:
bluesky:
- a.bsky.social
Expand All @@ -47,17 +41,19 @@ hashtags:
---
Your text content goes here.

![A](https://example.com/a.jpg)
![B](https://example.org/b.png)
```
**Notes on the Template:**
- Everything between the two `---` are metatags and should be in YAML format.

- "media" (Required): Ensure the media name is implemented inside the `plugins.yml`.

- "images" (Optional): Include links to desired images. The alt_text is optional but recommended.

- "mentions" and "hashtags" (Optional): Follow the specified format as shown in the template.

- "Your text content goes here." (Required): This is the content that will be posted to social media platforms. When the character limit is reached on a social media, it will be divided into several posts as a thread.
- "Your text content goes here." (Required): This is the content that will be posted to social media platforms. When the character limit is reached on a social media, it will be divided into several posts as a thread. Note that some social media platforms do not support Markdown formatting, so use plain text only.

- "images" (Optional): You can include images using Markdown format at the end of the file like this: `![Alternative text](Link to the image)`. Alternatively, you can simply drag and drop an image from your PC while adding your file.

4. **Create a Pull Request:** Once your post is ready, [create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request?tool=webui#creating-the-pull-request) to the main branch from another branch or [from your fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork)

Expand Down
20 changes: 12 additions & 8 deletions lib/galaxy_social.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import json
import os
import re
import sys
from argparse import ArgumentParser
from fnmatch import filter
from importlib import import_module

from bs4 import BeautifulSoup
from jsonschema import validate
from markdown import markdown
from yaml import safe_load as yaml


Expand Down Expand Up @@ -79,8 +78,8 @@ def parse_markdown_file(self, file_path):
result, status = self.lint_markdown_file(file_path)
if not status:
raise Exception(f"Failed to parse {file_path}.\n{result}")
metadata, text = result

metadata, text = result

metadata["media"] = [media.lower() for media in metadata["media"]]

Expand All @@ -100,10 +99,15 @@ def parse_markdown_file(self, file_path):
if metadata.get("hashtags")
else {}
)
markdown_content = markdown(text.strip())
plain_content = BeautifulSoup(markdown_content, "html.parser").get_text(
separator="\n"
)

image_pattern = re.compile(r"!\[(.*?)\]\((.*?)\)")
images = image_pattern.findall(text)
plain_content = re.sub(image_pattern, "", text).strip()

metadata["images"] = metadata.get("images", [])
for image in images:
metadata["images"].append({"url": image[1], "alt_text": image[0]})

return plain_content, metadata

def process_markdown_file(self, file_path, processed_files):
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
aiofiles==23.2.1
atproto==0.0.46
beautifulsoup4==4.12.3
Markdown==3.6
Mastodon.py==1.8.1
matrix-nio==0.24.0
Pillow==10.3.0
Expand Down

0 comments on commit 78af8ab

Please sign in to comment.