Skip to content

Commit

Permalink
不同 cdn 用不同 icon 区分
Browse files Browse the repository at this point in the history
  • Loading branch information
lessfish committed Apr 6, 2019
1 parent 5f7751e commit 764bbc1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .cdnrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cdnjs
bootcdn
Binary file added bootcdn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cdnjs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
</array>
<key>3CF9F85E-725F-45D8-8DDD-5B883EBBDA4C</key>
<array/>
<key>51CA00DD-A488-4B02-86EA-80AB053DBAF8</key>
<array/>
<key>5E78EC69-6D31-432F-BFCC-49839E43246E</key>
<array>
<dict>
Expand Down
8 changes: 7 additions & 1 deletion lib/getDetailResult.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const get = require('./../util/get')
const path = require('path')

/**
* 根据 keyword 以及选用的 cdn 获取详细的 cdn 列表
Expand All @@ -8,14 +9,16 @@ const get = require('./../util/get')
function getDetailResult(cdnName, keyword) {
return new Promise(async resolve => {
let result = []
let url, cdnPrefix
let url, cdnPrefix, iconPath

if (cdnName === 'bootcdn') {
url = `https://api.bootcdn.cn/libraries/${keyword}.min.json`
cdnPrefix = 'cdn.bootcss.com'
iconPath = path.join(__dirname, './../bootcdn.png')
} else if (cdnName === 'cdnjs') {
url = `https://api.cdnjs.com/libraries/${keyword}`
cdnPrefix = `cdnjs.cloudflare.com/ajax/libs`
iconPath = path.join(__dirname, './../cdnjs.png')
}

let jsonContent = await get(url)
Expand All @@ -27,6 +30,9 @@ function getDetailResult(cdnName, keyword) {

result.push({
title: name,
icon: {
path: iconPath
},
arg: name // 按回车后,alfred 会把这个变量传递给下个步骤
})
}
Expand Down
8 changes: 8 additions & 0 deletions lib/getSearchResult.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const getBootcdnNames = require('./getBootcdnNames')
const get = require('./../util/get')
const path = require('path')

/**
* 根据关键字查询库名
Expand All @@ -18,17 +19,24 @@ function getSearchResult(cdnName, keyword) {
if (name.includes(keyword)) {
result.push({
title: name,
icon: {
path: path.join(__dirname, './../bootcdn.png'),
},
// subtitle: name,
arg: name // 按回车后,alfred 会把这个变量传递给下个步骤
})
}
}
} else if (cdnName === 'cdnjs') {
let content = await get(`https://api.cdnjs.com/libraries?search=${keyword}`)
// let content = await get(`https://api.cdnjs.com/libraries?search=${keyword}&fields=assets`)

for (let item of content.results) {
result.push({
title: item.name,
icon: {
path: path.join(__dirname, './../cdnjs.png'),
},
// subtitle: name,
arg: item.name // 按回车后,alfred 会把这个变量传递给下个步骤
})
Expand Down

0 comments on commit 764bbc1

Please sign in to comment.