📝 Cross-Post Project Update: Regex, Bug Fixes, and More Regex!

jesse_chong_3bcc276c4f950

Jesse Chong

Posted on November 4, 2024

📝 Cross-Post Project Update: Regex, Bug Fixes, and More Regex!

Image description

Image description

Image description

🪞 Reflecting on Last Week’s Progress:
When cross-posting from Medium to LinkedIn and DEV.to, I noticed several formatting issues: bold and italic text, as well as ordered and unordered lists, were not displaying correctly. Tags were also not posting accurately, and the URL linking back to the original article didn’t work as expected. After some adjustments, formatting is now accurate, and tags are correctly formatted for each platform.

📈 Project Update Overview:
DEV.to uses Markdown syntax, while LinkedIn does not. LinkedIn also has a 1300-character limit and lacks consistent support for bold and italic formatting. I developed a helper function that formats posts for LinkedIn and DEV.to, adjusting based on the platform input.

🗝️ Key Updates:
Regex Improvements: Posts are now formatted correctly for LinkedIn and DEV.to.
Tag Extraction from HTML: Tags are properly formatted for each platform.
Canonical URL Cleanup: Query parameters are removed, so the original article URL now works correctly.

🫨 Challenges & Solutions 💡

Challenge 1: Bold, italics, and lists weren’t properly formatted for DEV.to and LinkedIn.

Solution:

  1. LinkedIn doesn’t support bold, italics, or bullet points, so these were replaced with plain text, with numbers used for bullet points.
  2. After converting HTML to Markdown, ensured proper formatting (e.g., italics, bold).

Challenge 2: Tags from Medium weren’t cross-posting correctly.

  1. DEV.to limits tags to four, requiring lowercase alphanumeric tags in an array format.
  2. LinkedIn allows hashtags to be embedded, but they must be camelCase (no spaces or dashes) and limited to 1300 characters.

Solution:
Adjust tags to meet each platform’s requirements.

  1. For DEV.to: Remove non-alphanumeric characters, convert tags to lowercase, and limit to four tags.
  2. For LinkedIn: Remove any prefix hashtags, convert spaces or dashes to camelCase, and re-add the #.
  3. Kept content within 1200 characters to allow room for title, URL, and tags.

Challenge 3: Medium’s RSS feed sometimes includes unnecessary query parameters in URLs.

Solution:
Extract the clean URL for cross-posting.

🌟 Reflection:
Working with regex has been fascinating; it’s powerful and versatile for various use cases. I’ve used it before in my Fresh Start project for translating directions, which showed me how effective it can be. That said, regex has limitations, so it’s essential to use it cautiously, depending on your needs.

🔗 Check Out the Repo: https://github.com/Jesse-Chong/Cross-post-server

Thank you for reading! I’d love to hear your thoughts.

💖 💪 🙅 🚩
jesse_chong_3bcc276c4f950
Jesse Chong

Posted on November 4, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related