diff --git a/common/new-contract.ts b/common/new-contract.ts index 9ee82c9f..99f27874 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -19,7 +19,7 @@ export function getNewContract( calcStartPool(initialProb, ante) const tags = parseTags( - `${extraTags.map((tag) => `#${tag}`).join(' ')} ${question} ${description}` + `${question} ${description} ${extraTags.map((tag) => `#${tag}`).join(' ')}` ) const lowercaseTags = tags.map((tag) => tag.toLowerCase()) diff --git a/common/util/parse.ts b/common/util/parse.ts index 99e5a82c..1499a5c2 100644 --- a/common/util/parse.ts +++ b/common/util/parse.ts @@ -3,19 +3,25 @@ export function parseTags(text: string) { const matches = (text.match(regex) || []).map((match) => match.trim().substring(1) ) - const tagSet = new Set(matches) + const tagSet = new Set() const uniqueTags: string[] = [] - tagSet.forEach((tag) => uniqueTags.push(tag)) + // Keep casing of last tag. + matches.reverse() + for (const tag of matches) { + const lowercase = tag.toLowerCase() + if (!tagSet.has(lowercase)) { + tagSet.add(lowercase) + uniqueTags.push(tag) + } + } + uniqueTags.reverse() return uniqueTags } export function parseWordsAsTags(text: string) { - const regex = /(?:^|\s)(?:#?[a-z0-9_]+)/gi - const matches = (text.match(regex) || []) - .map((match) => match.replace('#', '').trim()) - .filter((tag) => tag) - const tagSet = new Set(matches) - const uniqueTags: string[] = [] - tagSet.forEach((tag) => uniqueTags.push(tag)) - return uniqueTags + const taggedText = text + .split(/\s+/) + .map((tag) => `#${tag}`) + .join(' ') + return parseTags(taggedText) } diff --git a/web/components/contract-card.tsx b/web/components/contract-card.tsx index e682c12a..77d32166 100644 --- a/web/components/contract-card.tsx +++ b/web/components/contract-card.tsx @@ -142,12 +142,9 @@ export function AbbrContractDetails(props: { export function ContractDetails(props: { contract: Contract }) { const { contract } = props - const { question, description, closeTime, creatorName, creatorUsername } = - contract + const { closeTime, creatorName, creatorUsername } = contract const { truePool, createdDate, resolvedDate } = contractMetrics(contract) - const tags = parseTags(`${question} ${description}`).map((tag) => `#${tag}`) - return (