-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(route): bloomberg api 404 error (#12834)
* fix bloomberg api 404 error * fix(route): AP News时区调整 (#12842) * feat(route): add 爱思想专题 (#12845) * chore: bring back lint-staged (#12844) * chore: bring back lint-staged * fix: gha label * fix: yml format * newsletter ok * forget to remove debug * fix(route): qidian chapter (#12850) * fix(route): qidian chapter * fix: chapter and forum author refs: #414 #501 #732 * fix(route): agefans (#12851) * feat(route): add V2rayShare (#12843) * add V2rayShare * style: auto format * add V2rayShare * style: auto format * Update docs/other.md * Update lib/v2/v2rayshare/maintainer.js * Update index.js * style: auto format * Update lib/v2/v2rayshare/index.js --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * chore(deps): bump fluxninja/openai-pr-reviewer from 0 to 1 (#12852) * chore(deps): bump fluxninja/openai-pr-reviewer from 0 to 1 Bumps [fluxninja/openai-pr-reviewer](https://github.com/fluxninja/openai-pr-reviewer) from 0 to 1. - [Release notes](https://github.com/fluxninja/openai-pr-reviewer/releases) - [Commits](coderabbitai/ai-pr-reviewer@v0...v1) --- updated-dependencies: - dependency-name: fluxninja/openai-pr-reviewer dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix: don't relabel for `dependabot[bot]` --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: twitter keyword * feat(route): 支持上海市文旅局审批公告 (#12862) * feat(route): 支持上海市文旅局审批公告 * fix(route): wgj * fix(route): currentUrl * fix(route): search params * feat: increase the timeout time for the fulltext_mode test * feat: support reverse proxy * style: auto format * fix: typo * test: fix empty request error * feat: bypass reverse proxy for requests with cookies * test: fix empty request error and remove node 16 support * fix: reverse proxy fails for some requests * feat: exclude some requests for reverse proxy * feat: expand the scope of retries and set proxy strategy * fix: logger.debug * fix(route/twitter): mixed media incomplete (#12863) * fix(route/twitter): media t.co links not purged (#12864) * Add fix for bloomberg newsletter * Fix deepscan error --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Andvari <31068367+dzx-dzx@users.noreply.github.com> Co-authored-by: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Co-authored-by: 钛白 <86600901+77taibai@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: DIYgod <i@diygod.me> Co-authored-by: GideonSenku <39037656+GideonSenku@users.noreply.github.com> Co-authored-by: Rongrong <i@rong.moe> Co-authored-by: Chenfei Xu <chenfxu@ebay.com>
- Loading branch information
1 parent
a832e97
commit 1f640b0
Showing
3 changed files
with
239 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,181 @@ | ||
const art = require('art-template'); | ||
const path = require('path'); | ||
const { processVideo } = require('./utils'); | ||
|
||
const nodeRenderers = { | ||
paragraph: (node, nextNode) => `<p>${nextNode(node.content)}</p>`, | ||
text: (node) => { | ||
const { attributes: attr, value: val } = node; | ||
if (attr?.emphasis && attr?.strong) { | ||
return `<strong><em>${val}</em></strong>`; | ||
} else if (attr?.emphasis) { | ||
return `<em>${val}</em>`; | ||
} else if (attr?.strong) { | ||
return `<strong>${val}</strong>`; | ||
} else { | ||
return val; | ||
} | ||
}, | ||
'inline-newsletter': (node, nextNode) => `<div>${nextNode(node.content)}</div>`, | ||
heading: (node, nextNode) => { | ||
const nodeData = node.data; | ||
if (nodeData.level === 2 || nodeData.level === 3) { | ||
return `<h3>${nextNode(node.content)}</h3>`; | ||
} | ||
}, | ||
link: (node, nextNode) => { | ||
const dest = node.data.destination; | ||
const web = dest.web; | ||
const bbg = dest.bbg; | ||
const title = node.data.title; | ||
if (web) { | ||
return `<a href="${web}" title="${title}" target="_blank">${nextNode(node.content)}</a>`; | ||
} | ||
|
||
if (bbg && bbg.startsWith('bbg://news/stories')) { | ||
const o = bbg.split('bbg://news/stories/').pop(); | ||
const s = 'https://www.bloomberg.com/news/terminal/'.concat(o); | ||
return `<a href="${s}" title="${title}" target="_blank">${nextNode(node.content)}</a>`; | ||
} | ||
return String(nextNode(node.content)); | ||
}, | ||
entity: (node, nextNode) => { | ||
const t = node.subType; | ||
const linkDest = node.data.link.destination; | ||
const web = linkDest.web; | ||
if (t === 'person') { | ||
return String(nextNode(node.content)); | ||
} | ||
if (t === 'story') { | ||
if (web) { | ||
return `<a href="${web}" target="_blank">${nextNode(node.content)}</a>`; | ||
} | ||
const a = node.data.story.identifiers.suid; | ||
const o = 'https://www.bloomberg.com/news/terminal/'.concat(a); | ||
return `<a href="${o}" target="_blank">${nextNode(node.content)}</a>`; | ||
} | ||
if (t === 'security') { | ||
const s = node.data.security.identifiers.parsekey; | ||
if (s) { | ||
const c = s.split(' '); | ||
const href = 'https://www.bloomberg.com/quote/'.concat(c[0], ':').concat(c[1]); | ||
return `<a href="${href}" target="_blank">${nextNode(node.content)}</a>`; | ||
} | ||
} | ||
return String(nextNode(node.content)); | ||
}, | ||
br: () => `<br/>`, | ||
hr: () => `<br/>`, | ||
ad: () => {}, | ||
blockquote: (node, nextNode) => `<blockquote>${nextNode(node.content)}</blockquote>`, | ||
quote: (node, nextNode) => `<blockquote>${nextNode(node.content)}</blockquote>`, | ||
aside: (node, nextNode) => `<aside>${nextNode(node.content)}</aside>`, | ||
list: (node, nextNode) => { | ||
const t = node.subType; | ||
if (t === 'unordered') { | ||
return `<ul>${nextNode(node.content)}</ul>`; | ||
} | ||
if (t === 'ordered') { | ||
return `<ol>${nextNode(node.content)}</ol>`; | ||
} | ||
}, | ||
listItem: (node, nextNode) => `<li>${nextNode(node.content)}</li>`, | ||
media: (node) => { | ||
const t = node.subType; | ||
if (t === 'chart' && node.data.attachment) { | ||
if (node.data.attachment.creator === 'TOASTER') { | ||
const c = node.data.chart; | ||
const e = { | ||
src: (c && c.fallback) || '', | ||
chart: node.data.attachment, | ||
id: (c && c.id) || '', | ||
alt: (c && c.alt) || '', | ||
}; | ||
const w = e.chart; | ||
|
||
const chart = { | ||
source: w.source, | ||
footnote: w.footnote, | ||
url: w.url, | ||
title: w.title, | ||
subtitle: w.subtitle, | ||
chartId: 'toaster-chart-'.concat(e.id), | ||
chartAlt: e.alt, | ||
fallback: e.src, | ||
}; | ||
return art(path.join(__dirname, 'templates/chart_media.art'), { chart }); | ||
} | ||
const image = { | ||
alt: node.data.attachment?.footnote || '', | ||
caption: node.data.attachment?.title + node.data.attachment.subtitle || '', | ||
credit: node.data.attachment?.source || '', | ||
src: node.data.chart?.fallback || '', | ||
}; | ||
return art(path.join(__dirname, 'templates/image_figure.art'), image); | ||
} | ||
if (t === 'photo') { | ||
const h = node.data; | ||
let img = ''; | ||
if (h.attachment) { | ||
const image = { src: h.photo?.src, alt: h.photo?.alt, caption: h.photo?.caption, credit: h.photo?.credit }; | ||
img = art(path.join(__dirname, 'templates/image_figure.art'), image); | ||
} | ||
if (h.link && h.link.destination && h.link.destination.web) { | ||
const href = h.link.destination.web; | ||
return `<a href="${href}" target="_blank">${img}</a>`; | ||
} | ||
return img; | ||
} | ||
if (t === 'video') { | ||
const h = node.data; | ||
const id = h.attachment && h.attachment.id; | ||
return processVideo(id); | ||
} | ||
if (t === 'audio' && node.data.attachment) { | ||
const B = node.data.attachment; | ||
const P = B.title; | ||
const D = B.url; | ||
const M = B.image; | ||
if (P && D) { | ||
const audio = { | ||
src: D, | ||
img: M, | ||
caption: P, | ||
credit: '', | ||
}; | ||
return art(path.join(__dirname, 'templates/audio_media.art'), audio); | ||
} | ||
} | ||
return ''; | ||
}, | ||
}; | ||
|
||
const nodeToHtmlString = (node, obj) => { | ||
const nextNode = (nodes) => nodeListToHtmlString(nodes); | ||
if (!node.type || !nodeRenderers[node.type]) { | ||
return `<node>${node.type}</node>`; | ||
} | ||
return nodeRenderers[node.type](node, nextNode, obj); | ||
}; | ||
|
||
const nodeListToHtmlString = (nodes) => | ||
nodes | ||
.map((node, index) => | ||
nodeToHtmlString(node, { | ||
index, | ||
prev: nodes[index - 1]?.type, | ||
next: nodes[index + 1]?.type, | ||
}) | ||
) | ||
.join(''); | ||
|
||
const documentToHtmlString = (document) => { | ||
if (!document || !document.content) { | ||
return ''; | ||
} | ||
return nodeListToHtmlString(document.content); | ||
}; | ||
|
||
module.exports = { | ||
documentToHtmlString, | ||
}; |
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,21 @@ | ||
<figure> | ||
{{if chart.title}} | ||
{{chart.title}} | ||
{{/if}} | ||
{{if chart.subtitle}} | ||
<p>{{chart.subtitle}}</p> | ||
{{/if}} | ||
<noscript> | ||
<img src="{{ chart.fallback }}" alt="{{ chart.chartAlt }}" loading="lazy" style="display:block; margin-left:auto; margin-right:auto;" width:100%; /> | ||
</noscript> | ||
<iframe id="{{chart.chartId}}" title="{{chart.title}}" referrerpolicy="no-referrer" width=100% height=150vh frameborder=0 marginheight=0 marginwidth=0 | ||
loading="lazy" scrolling="no" style="border:0; margin:0; padding:0; width:100%; height:150vh;" src="{{ chart.url }}" ></iframe> | ||
{{if chart.source}} | ||
<figcaption> | ||
<div class="source">{{@ chart.source }}</div> | ||
{{if chart.footnote}} | ||
<p>{{chart.footnote}}</p> | ||
{{/if}} | ||
</figcaption> | ||
{{/if}} | ||
</figure> |
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