Skip to content

Commit e62d5df

Browse files
authored
Merge pull request #6 from wixun111/master
添加51cto网站和categories支持
2 parents 5148c55 + 96774ca commit e62d5df

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/markdown.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ export const formatMarkdownBody = (container, selectors, options, exec) => {
103103
})
104104
options.context.tag = tag
105105
}
106+
if (selectors.categories) {
107+
const categories = []
108+
queryAll(selectors.categories).map(item => {
109+
categories.push(item.innerText.replace(/(^[\n\s]+|[\n\s]+$)/g, ''))
110+
})
111+
options.context.categories = categories
112+
}
106113
if (options.link) {
107114
queryAll('a', markdownBody).map(item => item.href = item.title)
108115
}
@@ -147,6 +154,7 @@ const extract = async ({ markdownBody, selectors, options, exec, hook }) => {
147154
author: getText(selectors.userName),
148155
home: getUrl(location.origin, getAttribute('href', selectors.userLink)),
149156
tag: context.tag,
157+
categories: context.categories,
150158
description: markdownBody.innerText.replace(/^([\n\s]+)/g, '').replace(/\n/g, ' ').slice(0, 50) + '...',
151159
}, localOptions.tpl)
152160
const markdownDoc = html2markdown(info + getMarkdown(markdownBody), {})

src/websites/51CTO.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export const hosts = ['blog.51cto.com']
2+
3+
export const options = {
4+
origin: '51cto',
5+
link: false,
6+
br: true,
7+
code: false,
8+
selectors: {
9+
title: '.title',
10+
body: '.editor-preview-side',
11+
copyBtn: '.copy-btn',
12+
userName: '.username .blog-user',
13+
userLink: '.avatar-img',
14+
invalid: '',
15+
unpack: '',
16+
tag: '.mess-tag .shence_tag',
17+
categories: '.mess-tag .shence_cate'
18+
}
19+
}
20+
21+
export const hook = {}
22+
23+
export const config = {
24+
hosts,
25+
options,
26+
hook
27+
}
28+
29+
export default config

0 commit comments

Comments
 (0)