Add lz-string for encoding

This commit is contained in:
He4eT 2020-12-18 00:25:26 +05:00
commit 3393209fd2
3 changed files with 14 additions and 6 deletions

5
package-lock.json generated
View file

@ -9065,6 +9065,11 @@
"yallist": "^4.0.0"
}
},
"lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY="
},
"magic-string": {
"version": "0.25.7",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz",

View file

@ -27,6 +27,7 @@
"sirv-cli": "1.0.3"
},
"dependencies": {
"lz-string": "^1.4.4",
"preact": "^10.3.2",
"preact-render-to-string": "^5.1.4",
"preact-router": "^3.2.1",

View file

@ -2,6 +2,14 @@ import {h} from 'preact'
import {Link} from 'preact-router/match'
import ReactMarkdown from 'react-markdown'
import {
compressToEncodedURIComponent as encode,
decompressFromEncodedURIComponent as decode
} from 'lz-string'
const noop = _ => null
const ident = _ => _
const previewContorls = content => (
<header><nav>
<ul>
@ -14,12 +22,6 @@ const previewContorls = content => (
</ul>
</nav></header>)
const noop = _ => null
const ident = _ => _
const decode = x => decodeURIComponent(atob(x))
const encode = x => btoa(encodeURIComponent(x))
const Post = ({mode, payload, setMarkdown}) => {
const [controls, decodeFn, encodeFn] = {
preview: [previewContorls, ident, encode],