-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6d062f
commit bb961d8
Showing
11 changed files
with
1,222 additions
and
957 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,27 +7,17 @@ jobs: | |
build-deploy: | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '10.x' | ||
- run: npm install | ||
- run: npm run create:html | ||
- run: npm run create:ast | ||
|
||
# - name: Cache dependencies | ||
# uses: actions/cache@v1 | ||
# with: | ||
# path: ~/.npm | ||
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
# restore-keys: | | ||
# ${{ runner.os }}-node- | ||
|
||
- run: npm install | ||
- run: npm run start | ||
|
||
- name: Build and Deploy | ||
uses: peaceiris/[email protected] | ||
env: | ||
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} | ||
PUBLISH_BRANCH: gh-pages | ||
PUBLISH_DIR: ./dist | ||
- name: Deploy | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
node_modules/ | ||
dist | ||
dist/*.html | ||
dist/*.json | ||
npm-debug.log* | ||
package-lock.json | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { toVFile } from 'to-vfile' | ||
import remark from 'remark' | ||
import gfm from 'remark-gfm' | ||
import FS from 'fs-extra' | ||
|
||
const getHeadingText = (arr = [], title = '') => { | ||
arr.forEach(child => { | ||
title += child.value | ||
if (child.children && Array.isArray(child.children)) { | ||
title += getHeadingText(child.children, title) | ||
} | ||
}) | ||
return title; | ||
} | ||
|
||
const getSoftwareName = (obj, result = { title: '' }) => { | ||
if (obj.value) { | ||
result.title += obj.value | ||
} | ||
if (obj.url) { | ||
result.url = obj.url | ||
} | ||
if (obj.type === 'delete') { | ||
result.delete = true | ||
} | ||
if (obj.children && Array.isArray(obj.children)) { | ||
obj.children.forEach(child => { | ||
result = getSoftwareName(child, result) | ||
}) | ||
} | ||
return result | ||
} | ||
|
||
const getIconDetail = (data, url = '') => { | ||
if (data.type === 'imageReference' && data.identifier && /^(freeware\s+icon|oss\s+icon|app-store\s+icon|awesome-list\s+icon)/.test(data.identifier.toLocaleLowerCase())) { | ||
let type = '' | ||
if (/^(freeware\s+icon)/.test(data.identifier.toLocaleLowerCase())) { | ||
type = 'freeware' | ||
} | ||
if (/^(oss\s+icon)/.test(data.identifier.toLocaleLowerCase())) { | ||
type = 'oss' | ||
} | ||
if (/^(app-store\s+icon)/.test(data.identifier.toLocaleLowerCase())) { | ||
type = 'app-store' | ||
} | ||
if (/^(awesome-list\s+icon)/.test(data.identifier.toLocaleLowerCase())) { | ||
type = 'awesome-list' | ||
} | ||
return { type, url } | ||
} | ||
return false | ||
} | ||
|
||
/** | ||
* ```markdown | ||
* * [Atom](https://atom.io) - xxxxxxx. [![Open-Source Software][OSS Icon]](https://xxx) ![Freeware][Freeware Icon] [![Awesome List][awesome-list Icon]](https://xxx) | ||
* ``` | ||
*/ | ||
const getMarkIcons = (arr = [], parent = {}) => { | ||
let mark = { icons: [] } | ||
if (arr && Array.isArray(arr) && arr[1] && arr[1].type === 'text' && /^([\s]+)?-\s/.test(arr[1].value)) { | ||
mark = { ...mark, ...getSoftwareName(arr[0]) } | ||
arr = arr.filter(child => { | ||
const data = getIconDetail(child) | ||
if (data) { | ||
mark.icons.push(data) | ||
return false | ||
} | ||
if (child.type === 'link' && child.children && Array.isArray(child.children)) { | ||
const childArr = child.children.filter(d => getIconDetail(d)) | ||
if (childArr.length > 0) { | ||
childArr.forEach((item) => { | ||
mark.icons.push(getIconDetail(item, child.url)) | ||
}) | ||
return false | ||
} | ||
} | ||
if (child.type === 'text' && child.value.replace(/\s/g, '') === '') { | ||
return false | ||
} | ||
return true | ||
}); | ||
} | ||
return { children: [...arr], mark: { ...mark } } | ||
} | ||
|
||
const getMdToAST = (data = [], parent = {}) => { | ||
data = data.map((child) => { | ||
if (child.position) { | ||
delete child.position | ||
if (child.type === 'listItem') { | ||
delete child.checked | ||
delete child.spread; | ||
} | ||
if (child.type === 'paragraph' && parent.type === 'listItem') { | ||
const result = getMarkIcons(child.children, child) | ||
child = { ...child, ...result } | ||
} | ||
if (child.type === 'heading') { | ||
child.value = getHeadingText(child.children) | ||
delete child.children | ||
} | ||
} | ||
if (child.children && Array.isArray(child.children)) { | ||
child.children = getMdToAST(child.children, child) | ||
} | ||
return child | ||
}) | ||
return data | ||
} | ||
|
||
remark() | ||
.use(gfm) | ||
.use(() => (tree) => { | ||
const startIndex = tree.children.findIndex(item => item.type === 'html' && /<!--start-->/.test(item.value)) | ||
const endIndex = tree.children.findIndex(item => item.type === 'html' && /<!--end-->/.test(item.value)) | ||
const data = tree.children.slice(startIndex + 1, endIndex) | ||
const dataAST = getMdToAST([...data]) | ||
FS.outputJsonSync('./dist/awesome-mac.json', dataAST) | ||
console.log(' create file: ./dist/awesome-mac.json') | ||
}) | ||
.processSync(toVFile.readSync('README.md')) | ||
|
||
|
||
remark() | ||
.use(gfm) | ||
.use(() => (tree) => { | ||
const startIndex = tree.children.findIndex(item => item.type === 'html' && /<!--start-->/.test(item.value)) | ||
const endIndex = tree.children.findIndex(item => item.type === 'html' && /<!--end-->/.test(item.value)) | ||
const data = tree.children.slice(startIndex + 1, endIndex) | ||
const dataAST = getMdToAST([...data]) | ||
FS.outputJsonSync('./dist/awesome-mac.zh.json', dataAST) | ||
console.log(' create file: ./dist/awesome-mac.zh.json') | ||
}) | ||
.processSync(toVFile.readSync('README-zh.md')) |
Oops, something went wrong.