mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 05:09:46 +00:00
Сделать получение данных о проектах от wpapi; реализовать функции получения проектов (по id, по фильтру и без него)
This commit is contained in:
1 parent
8bbd3ed3cc
commit
d9433d616b
1 file changed
+41
-5
+41
-5
@@ -2,7 +2,8 @@ import * as WPAPI from 'wpapi';
|
|||||||
import { flatten } from 'lodash';
|
import { flatten } from 'lodash';
|
||||||
|
|
||||||
import reactPress from './reactPress';
|
import reactPress from './reactPress';
|
||||||
import projects from './projects.json';
|
import HTMLReactParser from 'html-react-parser/lib/index';
|
||||||
|
//import projects from './projects.json';
|
||||||
|
|
||||||
const wp = new WPAPI(
|
const wp = new WPAPI(
|
||||||
process.env.NODE_ENV === 'development'
|
process.env.NODE_ENV === 'development'
|
||||||
@@ -51,6 +52,9 @@ async function loadMedia() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mediaLibrary = await loadMedia();
|
||||||
|
console.log(mediaLibrary);
|
||||||
|
|
||||||
async function loadPosts() {
|
async function loadPosts() {
|
||||||
// Получаем рубрики
|
// Получаем рубрики
|
||||||
const responseCategories = await getAllContent(wp.categories());
|
const responseCategories = await getAllContent(wp.categories());
|
||||||
@@ -79,14 +83,35 @@ async function loadPosts() {
|
|||||||
return responsePosts;
|
return responsePosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mediaLibrary = await loadMedia();
|
|
||||||
console.log(mediaLibrary);
|
|
||||||
const posts = await loadPosts();
|
const posts = await loadPosts();
|
||||||
console.log(posts);
|
console.log(posts);
|
||||||
|
|
||||||
|
|
||||||
|
function createProjectList() {
|
||||||
|
const result = {};
|
||||||
|
|
||||||
|
for (let post of posts) {
|
||||||
|
if (post.categories.includes('projects')) {
|
||||||
|
const { image } = mediaLibrary['projects'].find(item => item.id === post.featured_media);
|
||||||
|
|
||||||
|
result[post.id] = {
|
||||||
|
id: post.id,
|
||||||
|
name: post.title.rendered,
|
||||||
|
tag: post.tags[0],
|
||||||
|
preview: image
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const projects = createProjectList();
|
||||||
|
console.log(projects);
|
||||||
|
|
||||||
export async function getPosts(name) {
|
export async function getPosts(name) {
|
||||||
try {
|
try {
|
||||||
const result = posts.filter(post => post.tags.includes(name))[0];
|
const result = posts.filter(post => post.id == name)[0];
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -112,11 +137,22 @@ export async function getMedia(category, target = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getProjects(id) {
|
export async function getProjectByID(id) {
|
||||||
try {
|
try {
|
||||||
if (typeof id != 'undefined') {
|
if (typeof id != 'undefined') {
|
||||||
return projects[id];
|
return projects[id];
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getProjects(filter) {
|
||||||
|
try {
|
||||||
|
if (typeof filter != 'undefined') {
|
||||||
|
return projects.filter(project => project.includes(filter));
|
||||||
|
}
|
||||||
|
|
||||||
return projects;
|
return projects;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in new issue
Block a user