Skip to content

Commit

Permalink
feat(extension): embed: maps (Google Map, AMap, Baidu Map)
Browse files Browse the repository at this point in the history
  • Loading branch information
mekery committed Apr 29, 2020
1 parent 141a00e commit 6a15551
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/views/OEmbedView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default {
return
}
this.link = this.originalLink
this.originalLink = result.originalLink
this.link = result.originalLink
this.src = result.src
console.log('result', result)
}
Expand Down
80 changes: 80 additions & 0 deletions src/data/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const VideoServices = [

export const MapServices = [
{ label: 'Google Map', value: 'google_map', icon: 'mdi-google-maps', color: 'blue' },
{ label: 'AMap', value: 'amap', svgIcon: 'amap' },
{ label: 'Baidu Map', value: 'baidu_map', svgIcon: 'baidu-map' },
]

Expand Down Expand Up @@ -86,6 +87,25 @@ export const EmbedServiceLink = {
src: 'https://v.qq.com/txp/iframe/player.html?vid=i0033cgr1vn',
srcPrefix: 'https://v.qq.com/txp/iframe/player.html?vid',
linkRule: 'v.qq.com\\/x\\/cover\\/\\w+\\/\\w+',
},
amap: {
link: 'https://www.amap.com/place/B000A84G4C',
src: 'https://www.amap.com/place/B000A84G4C',
srcPrefix: '',
linkRule: '\\.amap\\.com',
},
baidu_map: {
link: 'https://map.baidu.com/',
src: 'https://map.baidu.com/',
srcPrefix: '',
linkRule: 'map\\.baidu\\.com',
},
google_map: {
link: 'https://map.google.com/',
src: 'https://map.google.com/',
srcPrefix: '',
linkRule: 'https:\\/\\/www.google.com\\/maps\\/embed\\?pb=.+sus',
tips: 'Google Map > select location > Share > Embed a map > COPY HTML'
}
}

Expand Down Expand Up @@ -185,10 +205,62 @@ function getQQVideoSrc (originalLink, result) {
return result
}

function getAMapSrc (originalLink, result) {
let link = EmbedServiceLink.amap
let linkRule = link.linkRule
let regex = new RegExp(linkRule)
let match = originalLink.match(regex)
if (match && match.length > 0) {
result.validLink = true

result.src = originalLink
result.validId = true
} else {
result.validLink = false
}

return result
}

function getBaiduMapSrc (originalLink, result) {
let link = EmbedServiceLink.baidu_map
let linkRule = link.linkRule
let regex = new RegExp(linkRule)
let match = originalLink.match(regex)
if (match && match.length > 0) {
result.validLink = true

result.src = originalLink
result.validId = true
} else {
result.validLink = false
}

return result
}

function getGoogleMapSrc (originalLink, result) {
let link = EmbedServiceLink.google_map
let linkRule = link.linkRule
let regex = new RegExp(linkRule)
let match = originalLink.match(regex)
if (match && match.length > 0) {
result.validLink = true

result.src = match[0]
result.validId = true
} else {
result.validLink = false
}

return result
}

export const getServiceSrc = (service, originalLink) => {
let result = {
validLink: false,
validId: false,
originalLink: originalLink,
src: ''
}

Expand All @@ -201,6 +273,14 @@ export const getServiceSrc = (service, originalLink) => {
return getBilibiliSrc(originalLink, result)
case 'qqvideo':
return getQQVideoSrc(originalLink, result)
case 'amap':
return getAMapSrc(originalLink, result)
case 'baidu_map':
return getBaiduMapSrc(originalLink, result)
case 'google_map':
result = getGoogleMapSrc(originalLink, result)
result.originalLink = result.src
return result
}

return result
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en-us/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default {
bilibili: 'Bilibili',
qqvideo: 'QQ Video',
google_map: 'Google Map',
amap: 'AMap',
baidu_map: 'Baidu Map',
modao: 'Modao',
lanhu: 'Lanhu',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/pl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default {
bilibili: 'Bilibili',
qqvideo: 'QQ Video',
google_map: 'Google Map',
amap: 'AMap',
baidu_map: 'Baidu Map',
modao: 'Modao',
lanhu: 'Lanhu',
Expand Down
5 changes: 3 additions & 2 deletions src/i18n/zh-hans/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ export default {
iqiyi: '爱奇艺',
bilibili: 'Bilibili',
qqvideo: '腾讯视频',
google_map: 'Google Map',
baidu_map: 'Baidu Map',
google_map: '谷歌地图',
amap: '高德地图',
baidu_map: '百度',
modao: '墨刀',
lanhu: '蓝湖',
figma: 'Figma',
Expand Down
1 change: 1 addition & 0 deletions src/statics/service/amap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6a15551

Please sign in to comment.