Skip to content

Commit

Permalink
🩹 Add the Web Share Target API (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkamran80 authored and BetaHuhn committed Oct 29, 2021
1 parent 6acd3ef commit a726371
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
28 changes: 28 additions & 0 deletions client/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ export default {
} else if (link) {
$modal.replace('linkDetails', { link })
}
// Web Share Target API
const { searchParams } = new URL(window.location)
let sharedUrl = ''
const validateUrl = (string) => {
let url
try {
url = new URL(string)
} catch (_) {
return false
}
return url.protocol === 'http:' || url.protocol === 'https:'
}
if (searchParams.get('url') && validateUrl(searchParams.get('url'))) {
sharedUrl = searchParams.get('url')
} else if (searchParams.get('text') && validateUrl(searchParams.get('text'))) {
sharedUrl = searchParams.get('text')
} else if (searchParams.get('title') && validateUrl(searchParams.get('title'))) {
sharedUrl = searchParams.get('title')
}
if (sharedUrl) {
$modal.replace('addLink', { inputValue: sharedUrl })
}
},
data() {
return {
Expand Down
11 changes: 10 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ export default {
name: 'WebCrate App',
short_name: 'WebCrate',
description: `WebCrate helps you organize and share links, articles and more from around the web. It's more than just a bookmarking tool.`,
theme_color: '#F7F6F4'
theme_color: '#F7F6F4',
share_target: {
action: '/',
method: 'GET',
params: {
title: 'title',
text: 'text',
url: 'url'
}
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build:server": "tsc -p ./server/tsconfig.json",
"lint:nuxt": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
"lint:server": "eslint ./server/ --ext .ts",
"copy-templates": "cp ./server/views ./build/views -r && cp ./server/service/image/NotoColorEmoji.ttf ./build/service/image",
"copy-templates": "cp -R ./server/views ./build/views && cp ./server/service/image/NotoColorEmoji.ttf ./build/service/image",
"clean": "rimraf dist build .nuxt",
"postbuild:server": "npm run copy-templates",
"prebuild": "npm run clean",
Expand Down

0 comments on commit a726371

Please sign in to comment.