Add module of drive resources

This commit is contained in:
zhengyi 2023-12-28 11:13:30 +08:00
parent 8215ab73e5
commit cd1c7b3f55
11 changed files with 160 additions and 13 deletions

View File

@ -47,6 +47,13 @@ This is a info tips
---
git:[@github/justice2001/halo-plugin-vditor]
---
drive:baidu
name: 网站资源集合
link: https://www.baidu.com/
password: abcde
`
render()
})

BIN
src/icons/drive/ali.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1703730875005" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7787" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M157.520435 0h708.958984C953.08055-0.058514 1023.443968 69.822161 1023.999854 156.408663v711.182527C1023.443968 954.177692 953.065921 1024.058368 866.479419 1023.999854H157.520435C70.919304 1024.058368 0.555886 954.177692 0 867.59119V156.408663C0.555886 69.822161 70.933933-0.058514 157.520435 0z" fill="#FFFFFF" p-id="7788"></path><path d="M438.008623 167.146033a227.386482 227.386482 0 0 1 237.231509 86.147645 224.372997 224.372997 0 0 1 42.964108 115.858269c1.097143 15.828112 0.6144 31.743995-1.404342 47.469708l-0.906972 2.311314c-28.671996 0.146286-57.05142 6.026971-83.426731 17.261712a226.88911 226.88911 0 0 0-64.146276 42.569136c-5.412571 6.334171-11.746741 11.849141-17.568912 17.876112-20.085026 20.085026-40.857594 40.755194-61.14742 61.235191-5.909942 5.529599-11.029941 11.746741-17.466512 16.764341A211.924084 211.924084 0 0 0 317.147383 424.755139a171.563861 171.563861 0 0 0-41.545137-5.31017l-8.045713-0.512a192.248658 192.248658 0 0 1-1.901714-32.226739 217.951055 217.951055 0 0 1 24.590625-103.292328 227.181682 227.181682 0 0 1 147.777808-116.267869z m38.85348 103.906728a116.443412 116.443412 0 0 0-101.800214 112.552213 115.653469 115.653469 0 0 0 18.168683 65.53599 116.66284 116.66284 0 1 0 83.631531-178.088203z" fill="#2C61E4" p-id="7789"></path><path d="M715.892926 418.932969L716.799898 416.621655v2.311314a211.529113 211.529113 0 0 1 92.964558 401.568857 213.942827 213.942827 0 0 1-147.880208 14.453026 210.826941 210.826941 0 0 1-84.231302-44.470851 52.809135 52.809135 0 0 1-18.066283-40.755194 53.408907 53.408907 0 0 1 67.876562-50.190621 55.120449 55.120449 0 0 1 21.679539 11.746741 104.916099 104.916099 0 1 0 11.936913-169.574376 136.235866 136.235866 0 0 0-24.795425 20.479997L423.350797 774.436461a231.80431 231.80431 0 0 1-31.817139 28.11611 211.426713 211.426713 0 0 1-105.61827 38.85348 212.523855 212.523855 0 0 1-206.204314-112.054841 211.631513 211.631513 0 0 1 111.030842-295.935958 214.235398 214.235398 0 0 1 77.311989-14.467655l8.031084 0.512c12.317255 1.609143 23.639768 7.592227 31.919538 16.852112a53.511307 53.511307 0 0 1-7.738513 78.701703 54.506049 54.506049 0 0 1-29.213253 10.649599 106.013242 106.013242 0 0 0-60.22582 16.471769 104.813699 104.813699 0 0 0 94.661473 185.929116 108.426956 108.426956 0 0 0 42.071765-30.134853c41.954737-40.959994 83.017131-82.812331 124.781696-123.874725 6.436571-5.017599 11.55657-11.234741 17.466512-16.76434 20.085026-20.070397 40.769823-40.755194 61.14742-61.235192 5.822171-6.026971 12.141713-11.55657 17.554283-17.876111a226.88911 226.88911 0 0 1 63.956105-41.954737 215.537341 215.537341 0 0 1 83.426731-17.261712z" fill="#3377F9" p-id="7790"></path><path d="M275.572989 419.444969c14.028798 0.058514 27.984453 1.8432 41.559766 5.31017a211.924084 211.924084 0 0 1 155.20912 149.884322c-41.764565 41.062394-82.82696 82.92936-124.781696 123.889353a106.422842 106.422842 0 0 0 21.67954-41.354965 104.301699 104.301699 0 0 0-6.729142-71.592218 105.515871 105.515871 0 0 0-65.448219-55.617821 111.630613 111.630613 0 0 0-26.009597-4.315428 54.506049 54.506049 0 0 0 29.110853-10.63497 53.511307 53.511307 0 0 0 7.738513-78.701703 51.799764 51.799764 0 0 0-32.329138-16.86674z" fill="#D2402C" p-id="7791"></path></svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -1 +1,15 @@
@border-radius: 3px;
@secondary: #818181;
@secondary-light: #F4F4F4;
// Warning
@warn-color: #FF8C00;
@warn-bg-color: #FFFAED;
// DANGER
@danger-color: #C31919;
@danger-bg-color: #FFEDED;
// Success
@success-color: #05B800;
@success-bg: #F2FFED;
// Info
@info-color: #3478CD;
@info-bg: #F1F7FF;

44
src/less/drive.less Normal file
View File

@ -0,0 +1,44 @@
@import "constant";
.drive {
border: 1px solid @secondary-light;
border-radius: @border-radius;
padding: 10px;
display: flex;
align-items: center;
justify-content: space-between;
user-select: none;
.drive-info {
display: flex;
flex-direction: column;
gap: 5px;
.platform {
display: flex;
align-items: center;
.drive-icon {
width: 30px;
}
span {
font-size: 16px;
margin-left: 5px;
color: @info-color;
}
}
}
.download-info {
display: flex;
flex-direction: column;
align-items: center;
.drive-password {
color: @secondary;
font-size: 12px;
margin-top: 5px;
}
}
}

View File

@ -17,3 +17,18 @@
margin: 20px 15px;
}
.btn {
background-color: @info-color;
color: #ffffff;
padding: 5px 8px;
text-align: center;
border-radius: @border-radius;
font-size: 14px;
min-width: 80px;
text-decoration: none;
}
.error {
text-align: center;
color: @danger-color;
}

View File

@ -1,18 +1,6 @@
@import "constant";
@border-width: 6px;
@border-type: solid;
// Warning
@warn-color: #FF8C00;
@warn-bg-color: #FFFAED;
// DANGER
@danger-color: #C31919;
@danger-bg-color: #FFEDED;
// Success
@success-color: #05B800;
@success-bg: #F2FFED;
// Info
@info-color: #3478CD;
@info-bg: #F1F7FF;
.tips {
position: relative;

View File

@ -0,0 +1,74 @@
import {IOptions, Provider} from "./provider";
import "../less/drive.less"
import {RENDER_CLASS} from "../constant";
const PLATFORM_LIST: {[key: string]: Platform } = {
"baidu": {
icon: "/icons/drive/baidu.svg",
name: "百度网盘"
},
"ali": {
icon: "/icons/drive/ali.png",
name: "阿里云盘"
}
}
export class DriveProvider implements Provider {
check(type: string): boolean {
return type.startsWith("drive")
}
process(type: string, content: string, options: IOptions): string {
// Parse Content
const driveInfo = this.parseContent(type, content);
if (driveInfo instanceof Object) {
let html = `<div class="${RENDER_CLASS} drive">`;
// Platform info
const platform = `<div class="platform">` +
`<img class="drive-icon" src="${options.cdn}${PLATFORM_LIST[driveInfo.platform].icon}" alt="${driveInfo.platform}"/>` +
`<span>${PLATFORM_LIST[driveInfo.platform].name}</span>` +
`</div>`
html += `<div class="drive-info"> ${platform} <div class="drive-title">${driveInfo.name}</div></div>`
html += `<div class="download-info"><a class="btn" href="${driveInfo.link}" target="_blank">下载资源</a>`
if (driveInfo.password) {
html += `<div class="drive-password">提取码: ${driveInfo.password}</div>`
}
html += "</div>"
return html + "</div>";
}
return `<div class="${RENDER_CLASS} drive error">语法错误(${driveInfo})</div>`;
}
parseContent(type:string, content: string): DriveOptions | string {
const [_, platform] = type.split(":");
if (!PLATFORM_LIST[platform]) return `不支持的平台: ${platform}`
const info: DriveOptions = {
link: "",
name: "",
password: "",
platform: platform
}
content.split("\n").forEach(line => {
console.log(line.indexOf(":"))
const value = line.slice(line.indexOf(":") + 1).trim()
const key = line.slice(0, line.indexOf(":")) || ""
if (Object.keys(info).includes(key)) {
// @ts-ignore
info[key] = value
}
})
return info
}
}
interface DriveOptions {
link: string;
name: string;
password?: string;
platform: string;
}
interface Platform {
icon: string;
name: string;
}

View File

@ -1,8 +1,10 @@
import {TipsProvider} from "./tips-provider";
import {Provider} from "./provider";
import {GitProvider} from "./git-provider";
import {DriveProvider} from "./drive-provider";
export const ProviderList:Array<Provider> = [
new TipsProvider(),
new GitProvider()
new GitProvider(),
new DriveProvider()
]

View File

@ -77,6 +77,7 @@ module.exports = {
new CopyPlugin({
patterns: [
{from: "src/fonts", to: "fonts"},
{from: "src/icons", to: "icons"},
{from: "types", to: "types"}
]
})

View File

@ -55,6 +55,7 @@ module.exports = {
new CopyPlugin({
patterns: [
{from: "src/fonts", to: "fonts"},
{from: "src/icons", to: "icons"},
{from: "types", to: ""}
]
})