Skip to content

Commit

Permalink
fix: fix email
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope authored and ntnyq committed Feb 16, 2023
1 parent 64b4e76 commit 8686bd1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 36 deletions.
1 change: 0 additions & 1 deletion docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default defineUserConfig({
socialSharePlugin({
networks: ['qq', 'twitter', 'weibo', 'email', 'linkedin', 'pinterest', 'wechat'],
twitterUser: 'ntnyq',
email: 'ntnyq13@gmail.com',
fallbackImage: '/hero.png',
extendsNetworks,
}),
Expand Down
7 changes: 0 additions & 7 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ Currently, networks below are built-in supported:
- wechat <social-share class="list-demo-sns" :networks="['wechat']" />
- qrcode <social-share class="list-demo-sns" :networks="['qrcode']" />

### email

- **type:** `string`
- **default** `undefined`

Your email address.

::: warning Note
There is no single, standard way in which browsers/email clients handle mailto links (e.g. subject and body fields may be discarded without a warning). Also there is a risk that popup and ad blockers, anti-virus software etc. may silently block forced opening of mailto links.

Expand Down
2 changes: 1 addition & 1 deletion src/shared/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const BASE_NETWORKS: SocialShareNetworkData = {
icon: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path d="M352 608c38.4 0 64 25.6 64 64v128c0 38.4-25.6 64-64 64h-128c-38.4 0-64-25.6-64-64v-128c0-38.4 25.6-64 64-64h128m0-64h-128c-70.4 0-128 57.6-128 128v128c0 70.4 57.6 128 128 128h128c70.4 0 128-57.6 128-128v-128c0-70.4-57.6-128-128-128z"></path><path d="M320 800H256c-19.2 0-32-12.8-32-32v-64c0-19.2 12.8-32 32-32h64c19.2 0 32 12.8 32 32v64c0 19.2-12.8 32-32 32zM352 160c38.4 0 64 25.6 64 64v128c0 38.4-25.6 64-64 64h-128c-38.4 0-64-25.6-64-64v-128c0-38.4 25.6-64 64-64h128m0-64h-128c-70.4 0-128 57.6-128 128v128c0 70.4 57.6 128 128 128h128c70.4 0 128-57.6 128-128v-128c0-70.4-57.6-128-128-128z"></path><path d="M320 352H256c-19.2 0-32-12.8-32-32V256c0-19.2 12.8-32 32-32h64c19.2 0 32 12.8 32 32v64c0 19.2-12.8 32-32 32zM800 160c38.4 0 64 25.6 64 64v128c0 38.4-25.6 64-64 64h-128c-38.4 0-64-25.6-64-64v-128c0-38.4 25.6-64 64-64h128m0-64h-128c-70.4 0-128 57.6-128 128v128c0 70.4 57.6 128 128 128h128c70.4 0 128-57.6 128-128v-128c0-70.4-57.6-128-128-128z"></path><path d="M768 352h-64c-19.2 0-32-12.8-32-32V256c0-19.2 12.8-32 32-32h64c19.2 0 32 12.8 32 32v64c0 19.2-12.8 32-32 32z"></path><path d="M608 608m-32 0a32 32 0 1 0 64 0 32 32 0 1 0-64 0Z"></path><path d="M608 864m-32 0a32 32 0 1 0 64 0 32 32 0 1 0-64 0Z"></path><path d="M576 608h64v256H576z"></path><path d="M864 608m-32 0a32 32 0 1 0 64 0 32 32 0 1 0-64 0Z"></path><path d="M864 864m-32 0a32 32 0 1 0 64 0 32 32 0 1 0-64 0Z"></path><path d="M832 608h64v256h-64z"></path><path d="M736 608m-32 0a32 32 0 1 0 64 0 32 32 0 1 0-64 0Z"></path><path d="M736 864m-32 0a32 32 0 1 0 64 0 32 32 0 1 0-64 0Z"></path><path d="M704 608h64v256h-64z"></path></svg>',
},
email: {
sharer: 'mailto:@email?subject=@title&body=@url%0D%0A%0D%0A@description',
sharer: 'mailto:?subject=@title&body=@url%0D%0A%0D%0A@description',
type: 'direct',
color: '#d4237a',
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1117 1024"><path d="M53.865 558.08l289.92 121.6 560-492.16-491.52 530.56 371.84 140.8c8.96 3.2 19.2-1.28 22.4-10.24V848l260.48-816.64-1014.4 494.72c-8.96 4.48-12.16 14.72-8.32 23.68 2.56 3.84 5.76 7.04 9.6 8.32zm357.76 434.56l144.64-155.52-144.64-58.88v214.4z"/></svg>',
Expand Down
10 changes: 3 additions & 7 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export interface SocialShareFrontmatter {

export interface SocialSharePluginOptions {
networks?: string[]
email?: string
twitterUser?: string
fallbackImage?: string
isPlain?: boolean
Expand All @@ -59,9 +58,6 @@ export interface SocialSharePluginOptions {
extendsNetworks?: Record<string, SocialShareNetwork>
}

export type SocialSharePluginOptionsWithDefaults = Omit<
SocialSharePluginOptions & {
networksData: SocialShareNetworkData
},
'email'
>
export interface SocialSharePluginOptionsWithDefaults extends SocialSharePluginOptions {
networksData: SocialShareNetworkData
}
22 changes: 2 additions & 20 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,5 @@ import deepmerge from 'deepmerge'
import type { SocialSharePluginOptions } from './types.js'
import { BASE_NETWORKS } from './networks.js'

export const RE_EMAIL = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/

/**
* Check if given val is valid email address
* @param val given val
* @returns `true` if given an email address
*/
export const isEmail = (val: string) => RE_EMAIL.test(val)

export const createNetworksData = (options: SocialSharePluginOptions = {}) => {
const { email = '', extendsNetworks = {} } = options

if (isEmail(email)) {
BASE_NETWORKS.email.sharer = BASE_NETWORKS.email.sharer!.replace('@email', email)
} else {
delete BASE_NETWORKS.email
}

return deepmerge(BASE_NETWORKS, extendsNetworks)
}
export const createNetworksData = (options: SocialSharePluginOptions = {}) =>
deepmerge(BASE_NETWORKS, options.extendsNetworks || {})

1 comment on commit 8686bd1

@vercel
Copy link

@vercel vercel bot commented on 8686bd1 Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.