Remove #tag parsing
This commit is contained in:
parent
1f2c7271b7
commit
e2763f3dce
|
@ -12,7 +12,7 @@ import {
|
|||
visibility,
|
||||
} from './contract'
|
||||
import { User } from './user'
|
||||
import { parseTags, richTextToString } from './util/parse'
|
||||
import { richTextToString } from './util/parse'
|
||||
import { removeUndefinedProps } from './util/object'
|
||||
import { JSONContent } from '@tiptap/core'
|
||||
|
||||
|
@ -38,15 +38,6 @@ export function getNewContract(
|
|||
answers: string[],
|
||||
visibility: visibility
|
||||
) {
|
||||
const tags = parseTags(
|
||||
[
|
||||
question,
|
||||
richTextToString(description),
|
||||
...extraTags.map((tag) => `#${tag}`),
|
||||
].join(' ')
|
||||
)
|
||||
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
|
||||
|
||||
const propsByOutcomeType =
|
||||
outcomeType === 'BINARY'
|
||||
? getBinaryCpmmProps(initialProb, ante) // getBinaryDpmProps(initialProb, ante)
|
||||
|
@ -70,8 +61,8 @@ export function getNewContract(
|
|||
|
||||
question: question.trim(),
|
||||
description,
|
||||
tags,
|
||||
lowercaseTags,
|
||||
tags: [],
|
||||
lowercaseTags: [],
|
||||
visibility,
|
||||
isResolved: false,
|
||||
createdTime: Date.now(),
|
||||
|
|
|
@ -32,34 +32,6 @@ export function getUrl(text: string) {
|
|||
return results.length ? results[0].href : null
|
||||
}
|
||||
|
||||
export function parseTags(text: string) {
|
||||
const regex = /(?:^|\s)(?:[#][a-z0-9_]+)/gi
|
||||
const matches = (text.match(regex) || []).map((match) =>
|
||||
match.trim().substring(1).substring(0, MAX_TAG_LENGTH)
|
||||
)
|
||||
const tagSet = new Set()
|
||||
const uniqueTags: string[] = []
|
||||
// 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 taggedText = text
|
||||
.split(/\s+/)
|
||||
.map((tag) => (tag.startsWith('#') ? tag : `#${tag}`))
|
||||
.join(' ')
|
||||
return parseTags(taggedText)
|
||||
}
|
||||
|
||||
// TODO: fuzzy matching
|
||||
export const wordIn = (word: string, corpus: string) =>
|
||||
corpus.toLocaleLowerCase().includes(word.toLocaleLowerCase())
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
import * as admin from 'firebase-admin'
|
||||
import { uniq } from 'lodash'
|
||||
|
||||
import { initAdmin } from './script-init'
|
||||
initAdmin()
|
||||
|
||||
import { Contract } from '../../../common/contract'
|
||||
import { parseTags } from '../../../common/util/parse'
|
||||
import { getValues } from '../utils'
|
||||
|
||||
async function updateContractTags() {
|
||||
const firestore = admin.firestore()
|
||||
console.log('Updating contracts tags')
|
||||
|
||||
const contracts = await getValues<Contract>(firestore.collection('contracts'))
|
||||
|
||||
console.log('Loaded', contracts.length, 'contracts')
|
||||
|
||||
for (const contract of contracts) {
|
||||
const contractRef = firestore.doc(`contracts/${contract.id}`)
|
||||
|
||||
const tags = uniq([
|
||||
...parseTags(contract.question + contract.description),
|
||||
...(contract.tags ?? []),
|
||||
])
|
||||
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
|
||||
|
||||
console.log(
|
||||
'Updating tags',
|
||||
contract.slug,
|
||||
'from',
|
||||
contract.tags,
|
||||
'to',
|
||||
tags
|
||||
)
|
||||
|
||||
await contractRef.update({
|
||||
tags,
|
||||
lowercaseTags,
|
||||
} as Partial<Contract>)
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
updateContractTags().then(() => process.exit())
|
||||
}
|
|
@ -4,7 +4,7 @@ import { useState } from 'react'
|
|||
import Textarea from 'react-expanding-textarea'
|
||||
|
||||
import { Contract, MAX_DESCRIPTION_LENGTH } from 'common/contract'
|
||||
import { exhibitExts, parseTags } from 'common/util/parse'
|
||||
import { exhibitExts } from 'common/util/parse'
|
||||
import { useAdmin } from 'web/hooks/use-admin'
|
||||
import { useUser } from 'web/hooks/use-user'
|
||||
import { updateContract } from 'web/lib/firebase/contracts'
|
||||
|
@ -53,17 +53,7 @@ function RichEditContract(props: { contract: Contract; isAdmin?: boolean }) {
|
|||
|
||||
async function saveDescription() {
|
||||
if (!editor) return
|
||||
|
||||
const tags = parseTags(
|
||||
`${editor.getText()} ${contract.tags.map((tag) => `#${tag}`).join(' ')}`
|
||||
)
|
||||
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
|
||||
|
||||
await updateContract(contract.id, {
|
||||
description: editor.getJSON(),
|
||||
tags,
|
||||
lowercaseTags,
|
||||
})
|
||||
await updateContract(contract.id, { description: editor.getJSON() })
|
||||
}
|
||||
|
||||
return editing ? (
|
||||
|
|
Loading…
Reference in New Issue
Block a user