mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-04-17 23:51:44 +00:00
build
This commit is contained in:
56
dist/vadapav/posts.js
vendored
56
dist/vadapav/posts.js
vendored
@@ -1,56 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getSearchPosts = exports.getPosts = void 0;
|
||||
const getPosts = async function ({ filter, page,
|
||||
// providerValue,
|
||||
signal, providerContext, }) {
|
||||
const { getBaseUrl, axios, cheerio } = providerContext;
|
||||
const baseUrl = await getBaseUrl("vadapav");
|
||||
if (page > 1) {
|
||||
return [];
|
||||
}
|
||||
const url = `${baseUrl + filter}`;
|
||||
return posts({ baseUrl, url, signal, axios, cheerio });
|
||||
};
|
||||
exports.getPosts = getPosts;
|
||||
const getSearchPosts = async function ({ searchQuery, page,
|
||||
// providerValue,
|
||||
signal, providerContext, }) {
|
||||
const { getBaseUrl, axios, cheerio } = providerContext;
|
||||
const baseUrl = await getBaseUrl("vadapav");
|
||||
if (page > 1) {
|
||||
return [];
|
||||
}
|
||||
const url = `${baseUrl}/s/${searchQuery}`;
|
||||
return posts({ baseUrl, url, signal, axios, cheerio });
|
||||
};
|
||||
exports.getSearchPosts = getSearchPosts;
|
||||
async function posts({
|
||||
// baseUrl,
|
||||
url, signal, axios, cheerio, }) {
|
||||
try {
|
||||
const res = await axios.get(url, { signal });
|
||||
const data = res.data;
|
||||
const $ = cheerio.load(data);
|
||||
const catalog = [];
|
||||
$('.directory-entry:not(:contains("Parent Directory"))').map((i, element) => {
|
||||
const title = $(element).text();
|
||||
const link = $(element).attr("href");
|
||||
const imageTitle = title?.length > 30
|
||||
? title?.slice(0, 30)?.replace(/\./g, " ")
|
||||
: title?.replace(/\./g, " ");
|
||||
const image = `https://placehold.jp/23/000000/ffffff/200x400.png?text=${encodeURIComponent(imageTitle)}&css=%7B%22background%22%3A%22%20-webkit-gradient(linear%2C%20left%20bottom%2C%20left%20top%2C%20from(%233f3b3b)%2C%20to(%23000000))%22%2C%22text-transform%22%3A%22%20capitalize%22%7D`;
|
||||
if (title && link) {
|
||||
catalog.push({
|
||||
title: title,
|
||||
link: link,
|
||||
image: image,
|
||||
});
|
||||
}
|
||||
});
|
||||
return catalog;
|
||||
}
|
||||
catch (err) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user