forked from syuilo/summaly
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
14 changed files
with
145 additions
and
45 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 |
---|---|---|
|
@@ -31,4 +31,4 @@ jobs: | |
pnpm build | ||
- name: Test | ||
run: | | ||
pnpm test | ||
SKIP_NETWORK_TEST=true pnpm test |
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
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,26 @@ | ||
import * as cheerio from 'cheerio'; | ||
import type Summary from '@/summary.js'; | ||
import { getResponse, getGotOptions } from '@/utils/got.js'; | ||
import { parseGeneral, type GeneralScrapingOptions } from '@/general.js'; | ||
|
||
export function test(url: URL): boolean { | ||
return url.hostname === 'bsky.app'; | ||
} | ||
|
||
export async function summarize(url: URL, opts?: GeneralScrapingOptions): Promise<Summary | null> { | ||
const args = getGotOptions(url.href, opts); | ||
|
||
// HEADで取ると404が返るためGETのみで取得 | ||
const res = await getResponse({ | ||
...args, | ||
method: 'GET', | ||
}); | ||
const body = res.body; | ||
const $ = cheerio.load(body); | ||
|
||
return await parseGeneral(url, { | ||
body, | ||
$, | ||
response: res, | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import * as amazon from './amazon.js'; | ||
import * as bluesky from './bluesky.js'; | ||
import * as wikipedia from './wikipedia.js'; | ||
import * as branchIoDeeplinks from './branchio-deeplinks.js'; | ||
import { SummalyPlugin } from '@/iplugin.js'; | ||
|
||
export const plugins: SummalyPlugin[] = [ | ||
amazon, | ||
bluesky, | ||
wikipedia, | ||
branchIoDeeplinks, | ||
]; |
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
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,13 @@ | ||
<!doctype html> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="fediverse:creator" content="@[email protected]"> | ||
<title>Meow</title> | ||
</head> | ||
<body> | ||
<h1>Hellooo!</h1> | ||
<p>:3</p> | ||
</body> | ||
</html> |
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 |
---|---|---|
|
@@ -12,7 +12,7 @@ import { dirname } from 'node:path'; | |
import { fileURLToPath } from 'node:url'; | ||
import { Agent as httpAgent } from 'node:http'; | ||
import { Agent as httpsAgent } from 'node:https'; | ||
import { expect, test, describe, beforeEach, afterEach } from '@jest/globals'; | ||
import { expect, test, describe, beforeEach, afterEach, xtest } from '@jest/globals'; | ||
import fastify, { type FastifyInstance } from 'fastify'; | ||
import { summaly } from '../src/index.js'; | ||
import { StatusError } from '../src/utils/status-error.js'; | ||
|
@@ -36,6 +36,15 @@ process.on('unhandledRejection', console.dir); | |
|
||
let app: FastifyInstance | null = null; | ||
|
||
function skippableTest(name: string, fn: () => void) { | ||
if (process.env.SKIP_NETWORK_TEST === 'true') { | ||
console.log(`[SKIP] ${name}`); | ||
xtest(name, fn); | ||
} else { | ||
test(name, fn); | ||
} | ||
} | ||
|
||
afterEach(async () => { | ||
if (app) { | ||
await app.close(); | ||
|
@@ -73,10 +82,11 @@ test('basic', async () => { | |
sensitive: false, | ||
url: host + '/', | ||
activityPub: null, | ||
fediverseCreator: null, | ||
}); | ||
}); | ||
|
||
test('Stage Bye Stage', async () => { | ||
skippableTest('Stage Bye Stage', async () => { | ||
// If this test fails, you must rewrite the result data and the example in README.md. | ||
|
||
const summary = await summaly('https://www.youtube.com/watch?v=NMIEAhH_fTU'); | ||
|
@@ -102,6 +112,7 @@ test('Stage Bye Stage', async () => { | |
'sitename': 'YouTube', | ||
'sensitive': false, | ||
'activityPub': null, | ||
'fediverseCreator': null, | ||
'url': 'https://www.youtube.com/watch?v=NMIEAhH_fTU', | ||
}, | ||
); | ||
|
@@ -507,6 +518,36 @@ describe('ActivityPub', () => { | |
}); | ||
}); | ||
|
||
describe('Fediverse Creator', () => { | ||
test('Basic', async () => { | ||
app = fastify(); | ||
app.get('*', (request, reply) => { | ||
const content = fs.readFileSync(_dirname + '/htmls/fediverse-creator.html'); | ||
reply.header('content-length', content.length); | ||
reply.header('content-type', 'text/html'); | ||
return reply.send(content); | ||
}); | ||
await app.listen({ port }); | ||
|
||
const summary = await summaly(host); | ||
expect(summary.fediverseCreator).toBe('@[email protected]'); | ||
}); | ||
|
||
test('Null', async () => { | ||
app = fastify(); | ||
app.get('*', (request, reply) => { | ||
const content = fs.readFileSync(_dirname + '/htmls/basic.html'); | ||
reply.header('content-length', content.length); | ||
reply.header('content-type', 'text/html'); | ||
return reply.send(content); | ||
}); | ||
await app.listen({ port }); | ||
|
||
const summary = await summaly(host); | ||
expect(summary.fediverseCreator).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('sensitive', () => { | ||
test('default', async () => { | ||
app = fastify(); | ||
|