Skip to content

Commit

Permalink
fix:article edit
Browse files Browse the repository at this point in the history
  • Loading branch information
钱巍 committed Nov 14, 2024
1 parent 269f196 commit 02a8aec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
28 changes: 15 additions & 13 deletions lib/routes/logrocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import ofetch from '@/utils/ofetch'; // 统一使用的请求库
import { load } from 'cheerio'; // 类似 jQuery 的 API HTML 解析器
import { Route } from '@/types';
import cache from '@/utils/cache';
import { art } from '@/utils/render';
import { getCurrentPath } from '@/utils/helpers';
import path from 'node:path';
const __dirname = getCurrentPath(import.meta.url);
// import { getCurrentPath } from '@/utils/helpers';
// import { art } from '@/utils/render';
// import path from 'node:path';
// const __dirname = getCurrentPath(import.meta.url);
export const route: Route = {
path: '/:type',
categories: ['blog'],
Expand All @@ -25,15 +25,15 @@ export const route: Route = {
async function handler(ctx) {
const type = ctx.req.param('type');
const link = 'https://blog.logrocket.com/';
let title = '开发';
let title = 'Dev';
if (type === 'product-management') {
title = '产品管理';
title = 'Product Management';
} else if (type === 'ux-design') {
title = '用户体验设计';
title = 'UX Design';
}
const response = await ofetch(`${link}${type}`);
const $ = load(response);
const list = $('div.post-list .post-card')
const list = $('div.post-list .post-card')
.toArray()
.map((item) => {
item = $(item);
Expand All @@ -51,11 +51,13 @@ async function handler(ctx) {
cache.tryGet(item.link, async () => {
const response = await ofetch(item.link);
const $ = load(response);
// item.description = $('body').first().remove('#nav-bar-container').html();
item.description = art(path.join(__dirname, 'templates/description.art'), {
header: $('#post-header').html(),
description: $('div.content-max-width').html(),
});
//
$('div.content-max-width .sidebar-container div.code-block').remove();
item.description = $('div.content-max-width .sidebar-container').html();
// item.description = art(path.join(__dirname, 'templates/description.art'), {
// // header: $('#post-header').html(),
// description: $('div.content-max-width .the-content-container').remove('.lr-content div.code-block.code-block-77').remove('.lr-content .code-block.code-block-57').html(),
// });
return item;
})
)
Expand Down
4 changes: 0 additions & 4 deletions lib/routes/logrocket/templates/description.art
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{{ if header }}
{{@ header }}
{{ /if }}

{{ if description }}
{{@ description }}
{{ /if }}

0 comments on commit 02a8aec

Please sign in to comment.