sidebarDepth |
---|
3 |
vuepress-plugin-social-share is a VuePress plugin which provides social sharing services.
npm install vuepress-plugin-social-share@next -D
yarn add vuepress-plugin-social-share@next -D
pnpm add vuepress-plugin-social-share@next -D
See Official Docs about how to use a plugin in VuePress.
import { defineUserConfig } from 'vuepress'
import { socialSharePlugin } from 'vuepress-plugin-social-share'
export default defineUserConfig({
plugins: [socialSharePlugin()],
})
For advanced usage.
import { defineUserConfig } from 'vuepress'
import { socialSharePlugin } from 'vuepress-plugin-social-share'
import type { SocialShareNetworkData } from 'vuepress-plugin-social-share'
const extendsNetworks: SocialShareNetworkData = {
pinterest: {
sharer: 'https://pinterest.com/pin/create/button/?url=@url&media=@media&description=@title',
type: 'popup',
icon: '/pinterest.png',
},
linkedin: {
sharer:
'https://www.linkedin.com/shareArticle?mini=true&url=@url&title=@title&summary=@description',
type: 'popup',
color: '#1786b1',
icon: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path d="M910.336 0H113.664A114.005333 114.005333 0 0 0 0 113.664v796.672A114.005333 114.005333 0 0 0 113.664 1024h796.672A114.005333 114.005333 0 0 0 1024 910.336V113.664A114.005333 114.005333 0 0 0 910.336 0zM352.256 796.330667H207.189333V375.466667h145.066667z m-72.021333-477.866667a77.824 77.824 0 0 1-81.237334-74.069333A77.824 77.824 0 0 1 280.234667 170.666667a77.824 77.824 0 0 1 81.237333 73.728 77.824 77.824 0 0 1-81.237333 73.386666z m582.314666 477.866667H716.8v-227.669334c0-46.762667-18.432-93.525333-73.045333-93.525333a84.992 84.992 0 0 0-81.237334 94.549333v226.304h-140.629333V375.466667h141.653333v60.757333a155.989333 155.989333 0 0 1 136.533334-71.338667c60.416 0 163.498667 30.378667 163.498666 194.901334z" /></svg>',
},
twitter: {
color: '#f00',
},
}
export default defineUserConfig({
plugins: [
socialSharePlugin({
networks: ['twitter', 'facebook', 'email', 'pinterest', 'linkedin'],
twitterUser: 'ntnyq',
fallbackImage: '/social-share.png',
autoQuote: true,
isPlain: true,
qrcodeOptions: {
width: 240,
},
extendsNetworks,
}),
],
})
- type:
string[]
- default
['twitter', 'facebook', 'reddit']
Default networks set for all your social share components, no matter it's in global or local mode.
Currently, networks below are built-in supported:
- line
- skype
- telegram
- douban
- qrcode
::: 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.
Mailto only launches the MUA(Mail User Agent) which is configured as the default in the system-settings. :::
Reference:
- Automatically open default email client and pre-populate content
- Open email client through javascript
- type:
string
- default
undefined
Your Twitter profile username.
- type:
string
- default
undefined
A fallback share image if the page has no share image specified.
You can provide a network image url or an absolute path resolve based on .vuepress/public
.
import { defineUserConfig } from 'vuepress'
import { socialSharePlugin } from 'vuepress-plugin-social-share'
// Network image
export default defineUserConfig({
plugins: [
socialSharePlugin({
fallbackImage: 'https://vuepress.vuejs.org/hero.png',
}),
],
})
import { defineUserConfig } from 'vuepress'
import { socialSharePlugin } from 'vuepress-plugin-social-share'
// Public image file
export default defineUserConfig({
plugins: [
socialSharePlugin({
fallbackImage: '/hero.png',
}),
],
})
- type:
boolean
- default
true
For Facebook, use the share meta description as the share quote content.
- type:
boolean
- default
false
You can set isPlain
to true
if you don't like that all share icons have different colors.
All share icon colors will be set as the --c-brand by default.
Customize the color by setting --c-social-share-plain.
- type:
boolean
- default
false
You can disable the built-in style by setting useCustomStyle
to true
.
Then you can write styles that suit your theme.
You can take built-in style as a reference.
- type:
boolean
- default
false
Hide all SocialShare (global as well) when print.
- type:
object
- default:
{ errorCorrectionLevel: 'H', width: 250, scale: 1, margin: 1.5 }
We use qrcode to generate the qrcode image.
See it's options for more information.
- type:
object
- default
undefined
With this option, you can add your custom sharer or override the built-in networks config.
i.e:
import { defineUserConfig } from 'vuepress'
import { socialSharePlugin } from 'vuepress-plugin-social-share'
import type { SocialShareNetworkData } from 'vuepress-plugin-social-share'
const extendsNetworks: SocialShareNetworkData = {
pinterest: {
sharer: 'https://pinterest.com/pin/create/button/?url=@url&media=@media&description=@title',
type: 'popup',
icon: '/pinterest.png',
},
linkedin: {
sharer:
'https://www.linkedin.com/shareArticle?mini=true&url=@url&title=@title&summary=@description',
type: 'popup',
color: '#1786b1',
icon: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path d="M910.336 0H113.664A114.005333 114.005333 0 0 0 0 113.664v796.672A114.005333 114.005333 0 0 0 113.664 1024h796.672A114.005333 114.005333 0 0 0 1024 910.336V113.664A114.005333 114.005333 0 0 0 910.336 0zM352.256 796.330667H207.189333V375.466667h145.066667z m-72.021333-477.866667a77.824 77.824 0 0 1-81.237334-74.069333A77.824 77.824 0 0 1 280.234667 170.666667a77.824 77.824 0 0 1 81.237333 73.728 77.824 77.824 0 0 1-81.237333 73.386666z m582.314666 477.866667H716.8v-227.669334c0-46.762667-18.432-93.525333-73.045333-93.525333a84.992 84.992 0 0 0-81.237334 94.549333v226.304h-140.629333V375.466667h141.653333v60.757333a155.989333 155.989333 0 0 1 136.533334-71.338667c60.416 0 163.498667 30.378667 163.498666 194.901334z" /></svg>',
},
twitter: {
color: '#f00',
},
}
export default defineUserConfig({
plugins: [
socialSharePlugin({
networks: ['twitter', 'facebook', 'email', 'pinterest', 'linkedin'],
extendsNetworks,
}),
],
})
-
You need to specific the
extendsNetworks
option with an object whichkey
will be sharer's name andvalue
will be options -
Config the plugin's
networks
option if you want to add custom sharer toGlobalSocialShare
-
You can override the built-in networks config by given its options a different value
Custom sharer's option:
- type:
string
- required
true
You can use placeholders below in the sharer, it will be replaced by Share Meta
-
type:
string
-
default
undefined
-
required
true
-
popup
Open a new browser window for sharing service, mostly you need this -
direct
Open the sharer in current window directly. Formailto:
,sms:
and other built-in protocol -
qrcode
Open a model to show the qrcode of current page
The plugin does nothing if you haven't config type
properly.
- type:
string
- default
''
Set the svg element color if you use it as sharer's icon.
- type:
string
- required
true
You can set icon
with a network image, an image in your public folder with an absolute path or an svg element.
- type:
boolean
- default
false
Set it to true
if you want to disable the global social share component.
If you only want to disable global social share in some specific page, check Disable social share.
The props of SocialShare
component.
Same as the plugin's option networks, but with a higher priority.
- type:
string[]
- default
[]
Share tags for Twitter and Facebook.
Same as the plugin's option isPlain, but with a higher priority.
Meta data for social share services.
Each meta data are listed following its priority.
-
$frontmatter.$shareUrl
-
$frontmatter.shareUrl
-
location.href
-
$frontmatter.$shareTitle
-
$frontmatter.shareTitle
-
$frontmatter.title
-
document.title
-
$frontmatter.$shareDescription
-
$frontmatter.shareDescription
-
$frontmatter.description
-
<meta name="description" />'s content
-
themeConfig.description
-
$frontmatter.$shareImage
-
$frontmatter.shareImage
-
$frontmatter.image
-
plugin option's fallbackImage
-
$frontmatter.$shareQuote
-
$frontmatter.shareQuote
-
fallback to description when autoQuote is true.
-
$frontmatter.$shareTags
-
$frontmatter.shareTags
-
$frontmatter.tags
-
$frontmatter.tag
-
Component's prop tags
-
<meta name="keywords" />'s content
By default, those variables are set to vuepress-plugin-social-share.
:root {
// global trigger color
--c-social-share-trigger: var(--c-text-lightest);
// plain mode icon color
--c-social-share-plain: var(--c-brand);
// global bgColor
--c-bg-global-social-share: var(--c-bg);
}
Override it in your stylesheet if needed.
You can disable vuepress-plugin-social-share in a specific page by setting the markdown frontmatter.
Set noGlobalSocialShare
to true
if you want to disable the global social share component.
---
noGlobalSocialShare: true
---
Set noSocialShare
to true
if you want to disable all social share component.
---
noSocialShare: true
---