Skip to content

Commit

Permalink
add: type OGPFetchResult
Browse files Browse the repository at this point in the history
  • Loading branch information
TakahiroHimi committed Oct 16, 2021
1 parent 66032dd commit fffe4e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ogp-fetcher",
"version": "1.3.0",
"version": "1.4.0",
"description": "Library to fetch OGB",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
11 changes: 9 additions & 2 deletions src/fetchOgp.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import axios, { AxiosRequestHeaders } from "axios";
import { JSDOM } from "jsdom";

export type OGPFetchResult = {
url: string;
[key: string]: string;
}[];

/**
*
* @param targetUrls fetch target url list
* @returns ogp list
*/
export const fetchOgp = async (targetUrls: string[]) => {
export const fetchOgp = async (
targetUrls: string[]
): Promise<OGPFetchResult> => {
const headers: AxiosRequestHeaders = { "User-Agent": "bot" };

const fetches = targetUrls.map((url) => {
Expand Down Expand Up @@ -57,7 +64,7 @@ export const parseOgp = (htmlList: string[]) => {
*/
export const ogpFilter = (metaElements: NodeListOf<HTMLMetaElement>) => {
const ogps = [...Array(metaElements.length).keys()].reduce(
(prev: { [key: string]: string }, i) => {
(prev: { [property: string]: string }, i) => {
const property = metaElements.item(i).getAttribute("property")?.trim();
if (!property) return prev;
const content = metaElements.item(i).getAttribute("content");
Expand Down

0 comments on commit fffe4e7

Please sign in to comment.