Create new Blog Post #420
kentcdodds
started this conversation in
Share
Replies: 1 comment 3 replies
-
Love it! ❤️ Something I've been meaning to experiment with for "form-like", but text-only scenarios is pulling values out of an editor/textarea. My regex-foo has leveled-up thanks to all the Script Kit work, so I tossed this together. It parses out sections of an editor component, then you can do whatever you want with the values: let editorForm = `
## Title
## Description
## Tags
## Categories
`.trim()
let content = await editor(editorForm)
let getSectionContent = section => {
let r = new RegExp(
`(?<=##\\s+${section}\n)(.*?)(?=($(?!\n))|#)`,
"s"
)
return (content.match(r)?.[0] || "").trim()
}
let title = getSectionContent("Title")
let description = getSectionContent("Description")
let tags = getSectionContent("Tags")
let categories = getSectionContent("Categories")
inspect({
title,
description,
tags,
categories,
}) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm even using metascraper to scrape unsplash for an image, it's alt text, and author (unsplash does not make any of these things easy, yes I realize they have an API, but their terms say you have to hotlink to them if you use it and I don't want to).
I'm using cloudinary auto-uploads so I don't have to bother uploading the photo manually either :)
Install new-post
Beta Was this translation helpful? Give feedback.
All reactions