Files
RSSHub/lib/v2/bloomberg/react-renderer.js
T
1f640b07d2 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:
https://github.com/DIYgod/RSSHub/pull/414
https://github.com/DIYgod/RSSHub/pull/501
https://github.com/DIYgod/RSSHub/pull/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](https://github.com/fluxninja/openai-pr-reviewer/compare/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>
2023-07-24 22:44:56 +08:00

182 lines
6.5 KiB
JavaScript

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,
};