* Fold type, fold page, query for fold contracts * Tsconfig: target esnext, nounused locals: false * Store tags in field on contract. Script to update contract tags * Show tags on fold page * Load all fold comments server-side to serve better feed * Fix the annoying firebase already initialized error! * Add links to /edit and /leaderboards for fold * Page with list of folds * UI for creating a fold * Create a fold * Edit fold page
22 lines
654 B
TypeScript
22 lines
654 B
TypeScript
export function parseTags(text: string) {
|
|
const regex = /(?:^|\s)(?:[#][a-z0-9_]+)/gi
|
|
const matches = (text.match(regex) || []).map((match) =>
|
|
match.trim().substring(1)
|
|
)
|
|
const tagSet = new Set(matches)
|
|
const uniqueTags: string[] = []
|
|
tagSet.forEach((tag) => uniqueTags.push(tag))
|
|
return uniqueTags
|
|
}
|
|
|
|
export function parseWordsAsTags(text: string) {
|
|
const regex = /(?:^|\s)(?:[a-z0-9_]+)/gi
|
|
const matches = (text.match(regex) || [])
|
|
.map((match) => match.trim())
|
|
.filter((tag) => tag)
|
|
const tagSet = new Set(matches)
|
|
const uniqueTags: string[] = []
|
|
tagSet.forEach((tag) => uniqueTags.push(tag))
|
|
return uniqueTags
|
|
}
|