Be more lax about parsing links

This commit is contained in:
Jonathan Staab 2023-02-06 15:09:08 -06:00
parent 707a17d075
commit b4801a27a6
8 changed files with 29 additions and 33 deletions

View File

@ -69,6 +69,8 @@ If you like Coracle and want to support its development, you can donate sats via
- [x] Fixed likes not showing up in alerts
- [x] Raised threshold for pool to 2 so we don't have such a small amount of results
- [x] Wait for profile info on login, navigate to network by default
- [x] Fix mention selection, inheritance, and inclusion in notes
- [x] Parse links without http at the beginning
## 0.2.9

14
package-lock.json generated
View File

@ -15,7 +15,6 @@
"classnames": "^2.3.2",
"compressorjs": "^1.1.1",
"dexie": "^3.2.2",
"extract-urls": "^1.3.2",
"fuse.js": "^6.6.2",
"hurdak": "github:ConsignCloud/hurdak",
"husky": "^8.0.3",
@ -2135,14 +2134,6 @@
"safe-buffer": "^5.1.1"
}
},
"node_modules/extract-urls": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/extract-urls/-/extract-urls-1.3.2.tgz",
"integrity": "sha512-IqL5aDUYd3n4E0Y9sZewG3YVjyQ7LvH60YJHF8pFhzK4TSJGGdP342BhR+Gal0GeXR4NZc6H46bKTrBB73kwPA==",
"engines": {
"node": ">=10"
}
},
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@ -6654,11 +6645,6 @@
"safe-buffer": "^5.1.1"
}
},
"extract-urls": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/extract-urls/-/extract-urls-1.3.2.tgz",
"integrity": "sha512-IqL5aDUYd3n4E0Y9sZewG3YVjyQ7LvH60YJHF8pFhzK4TSJGGdP342BhR+Gal0GeXR4NZc6H46bKTrBB73kwPA=="
},
"fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",

View File

@ -10,7 +10,7 @@
"qa:lint": "eslint src/*/** --quiet",
"qa:check": "svelte-check --tsconfig ./tsconfig.json --threshold error",
"qa:all": "run-p qa:lint qa:check",
"watch": "find src -type f | entr -r npm run qa:all"
"watch": "find src -type f | entr -r"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^1.1.0",
@ -33,7 +33,6 @@
"classnames": "^2.3.2",
"compressorjs": "^1.1.1",
"dexie": "^3.2.2",
"extract-urls": "^1.3.2",
"fuse.js": "^6.6.2",
"hurdak": "github:ConsignCloud/hurdak",
"husky": "^8.0.3",

View File

@ -1,8 +1,8 @@
import {prop, pick, join, uniqBy, last} from 'ramda'
import {get} from 'svelte/store'
import {first} from "hurdak/lib/hurdak"
import {Tags, isRelay, roomAttrs} from 'src/util/nostr'
import {keys, publish, getRelays} from 'src/agent'
import {Tags, isRelay, roomAttrs, displayPerson} from 'src/util/nostr'
import {keys, publish, getRelays, getPerson} from 'src/agent'
const updateUser = (relays, updates) =>
publishEvent(relays, 0, {content: JSON.stringify(updates)})
@ -30,7 +30,13 @@ const createDirectMessage = (relays, pubkey, content) =>
publishEvent(relays, 4, {content, tags: [["p", pubkey]]})
const createNote = (relays, content, mentions = [], topics = []) => {
mentions = mentions.map(p => ["p", p, prop('url', first(getRelays(p)))])
mentions = mentions.map(p => {
const {url} = first(getRelays(p))
const name = displayPerson(getPerson(p, true))
return ["p", p, url, name]
})
topics = topics.map(t => ["t", t])
publishEvent(relays, 1, {content, tags: mentions.concat(topics)})

View File

@ -2,6 +2,7 @@
import {prop, reject, sortBy, last} from 'ramda'
import {fly} from 'svelte/transition'
import {fuzzy} from "src/util/misc"
import {displayPerson} from "src/util/nostr"
import {fromParentOffset} from "src/util/html"
import Badge from "src/partials/Badge.svelte"
import {people} from "src/agent/data"
@ -62,13 +63,14 @@
selection.collapse(space, 2)
}
const pickSuggestion = ({name, pubkey}) => {
highlightWord('@', getWord().length, name)
const pickSuggestion = person => {
const display = displayPerson(person)
highlightWord('@', getWord().length, display)
mentions.push({
name,
pubkey,
length: name.length + 1,
pubkey: person.pubkey,
length: display.length + 1,
end: getText().length - 2,
})
@ -181,9 +183,10 @@
<div class="rounded border border-solid border-medium mt-2 flex flex-col" in:fly={{y: 20}}>
{#each suggestions as person, i (person.pubkey)}
<button
class="py-2 px-4 cursor-pointer"
class="py-2 px-4 cursor-pointer border-l-2 border-solid border-black"
class:bg-black={index !== i}
class:bg-dark={index === i}
class:border-accent={index === i}
on:click={() => pickSuggestion(person)}>
<Badge inert {person} />
</button>

View File

@ -1,12 +1,12 @@
<script lang="ts">
import cx from 'classnames'
import extractUrls from 'extract-urls'
import {nip19} from 'nostr-tools'
import {whereEq, without, uniq, pluck, reject, propEq, find} from 'ramda'
import {slide} from 'svelte/transition'
import {navigate} from 'svelte-routing'
import {quantify} from 'hurdak/lib/hurdak'
import {Tags, findReply, findReplyId, displayPerson, isLike} from "src/util/nostr"
import {extractUrls} from "src/util/html"
import Preview from 'src/partials/Preview.svelte'
import Anchor from 'src/partials/Anchor.svelte'
import {settings, modal, renderNote} from "src/app"
@ -192,7 +192,7 @@
slot="addon"
on:click={sendReply}
class="flex flex-col py-8 p-4 justify-center gap-2 border-l border-solid border-dark
hover:bg-accent transition-all cursor-pointer text-white ">
hover:bg-accent transition-all cursor-pointer text-white">
<i class="fa fa-paper-plane fa-xl" />
</button>
</Compose>

View File

@ -1,5 +1,4 @@
import extractUrls from 'extract-urls'
import {first} from 'hurdak/lib/hurdak'
import {ellipsize} from 'hurdak/lib/hurdak'
export const copyToClipboard = text => {
const {activeElement} = document
@ -74,6 +73,9 @@ export const fromParentOffset = (element, offset): [HTMLElement, number] => {
throw new Error("Unable to find parent offset")
}
export const extractUrls = url =>
url.match(/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?!&//=]*)/gi)
export const renderContent = content => {
// Escape html
content = escapeHtml(content)
@ -87,7 +89,7 @@ export const renderContent = content => {
$a.className = "underline"
/* eslint no-useless-escape: 0 */
$a.innerText = first(url.replace(/https?:\/\/(www\.)?/, '').split(/[\/\?#]/))
$a.innerText = ellipsize(url.replace(/https?:\/\/(www\.)?/, ''), 50)
// If the url is on its own line, remove it entirely. Otherwise, replace it with the link
content = content.replace(url, $a.outerHTML)

View File

@ -20,11 +20,9 @@ export default defineConfig({
svelte({
preprocess: sveltePreprocess(),
onwarn: (warning, handler) => {
const isA11y = warning.code.startsWith('a11y-')
if (["a11y-autofocus"].includes(warning.code)) return
if (warning.code.startsWith('a11y-')) return
if (warning.filename.includes("node_modules")) return
if (warning.filename.includes("Card.svelte") && isA11y) return
handler(warning)
},