Skip to content

Commit

Permalink
Merge pull request #75 from Giveth/develop
Browse files Browse the repository at this point in the history
Support description html
  • Loading branch information
aminlatifi committed Jun 10, 2024
2 parents 9b5db5f + 64924c4 commit 763879e
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 15 deletions.
11 changes: 11 additions & 0 deletions db/migrations/1717941249030-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = class Data1717941249030 {
name = 'Data1717941249030'

async up(db) {
await db.query(`ALTER TABLE "project" ADD "description_html" text`)
}

async down(db) {
await db.query(`ALTER TABLE "project" DROP COLUMN "description_html"`)
}
}
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ethers": "^6.12.1",
"node-cron": "^3.0.3",
"pg": "^8.11.5",
"showdown": "^2.1.0",
"type-graphql": "^1.2.0-rc.1",
"typeorm": "^0.3.20",
"zod": "^3.23.8"
Expand All @@ -33,6 +34,7 @@
"@types/jest": "^29.5.12",
"@types/node": "^20.11.17",
"@types/node-cron": "^3.0.11",
"@types/showdown": "^2.0.6",
"jest": "^29.7.0",
"prettier": "^3.3.0",
"ts-jest": "^29.1.2",
Expand Down
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type Project @entity {
title: String
"Description of the project"
description: String
"Html format of description"
descriptionHtml: String
"Total attests with value True"
totalVouches: Int!
"Total attests with value False"
Expand Down
1 change: 1 addition & 0 deletions src/features/import-projects/gitcoin/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export const gitcoinSourceConfig: SourceConfig = {
descriptionField: "description",
imageField: "image",
urlField: "url",
descriptionHtmlField: "descriptionHtml",
};
8 changes: 7 additions & 1 deletion src/features/import-projects/gitcoin/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GitcoinProjectInfo } from "./type";
import { updateOrCreateProject } from "../helpers";
import { IPFS_GATEWAY, gitcoinSourceConfig } from "./constants";
import Showdown from "showdown";

const generateGitcoinUrl = (project: GitcoinProjectInfo) => {
const application = project.applications[0];
Expand All @@ -21,19 +22,24 @@ const convertIpfsHashToHttps = (hash: string) => {
return `${IPFS_GATEWAY}/${hash}`;
};

const converter = new Showdown.Converter();
export const processProjectsBatch = async (
projectsBatch: GitcoinProjectInfo[]
) => {
for (const project of projectsBatch) {
if (project.metadata?.type !== "project") continue;
const description = project.metadata?.description;
const processedProject = {
id: project.id,
title: project.name || project.metadata?.title,
description: project.metadata?.description,
description,
url: generateGitcoinUrl(project),
image: project.metadata?.bannerImg
? convertIpfsHashToHttps(project.metadata?.bannerImg)
: "",
descriptionHtml: description
? converter.makeHtml(description)
: undefined,
};
await updateOrCreateProject(processedProject, gitcoinSourceConfig);
}
Expand Down
38 changes: 24 additions & 14 deletions src/features/import-projects/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const updateOrCreateProject = async (
idField,
titleField,
descriptionField,
descriptionHtmlField,
urlField,
imageField,
} = sourConfig;
Expand All @@ -32,20 +33,28 @@ export const updateOrCreateProject = async (
.where("project.id = :id", { id })
.getOne();

const title = project[titleField];
const description = project[descriptionField];
const url = project[urlField];
const image = project[imageField];
const descriptionHtml = descriptionHtmlField && project[descriptionHtmlField];

if (existingProject) {
const isUpdated =
existingProject.title !== project[titleField] ||
existingProject.description !== project[descriptionField] ||
existingProject.url !== project[urlField] ||
existingProject.image !== project[imageField];
existingProject.title !== title ||
existingProject.description !== description ||
existingProject.url !== url ||
existingProject.image !== image ||
existingProject.descriptionHtml !== descriptionHtml;

if (isUpdated) {
const updatedProject = new Project({
...existingProject,
title: project[titleField],
description: project[descriptionField],
image: project[imageField],
url: project[urlField],
title,
description,
image,
url,
descriptionHtml,
lastUpdatedTimestamp: new Date(),
imported: true,
});
Expand All @@ -64,12 +73,13 @@ export const updateOrCreateProject = async (
} else {
const newProject = new Project({
id,
title: project[titleField],
description: project[descriptionField],
image: project[imageField],
url: project[urlField],
projectId: projectId,
source: source,
title,
description,
image,
url,
descriptionHtml,
projectId,
source,
totalVouches: 0,
totalFlags: 0,
totalAttests: 0,
Expand Down
1 change: 1 addition & 0 deletions src/features/import-projects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ interface SourceConfig {
idField: string;
titleField: string;
descriptionField: string;
descriptionHtmlField?: string;
urlField: string;
imageField: string;
}
6 changes: 6 additions & 0 deletions src/model/generated/project.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export class Project {
@Column_("text", {nullable: true})
description!: string | undefined | null

/**
* Html format of description
*/
@Column_("text", {nullable: true})
descriptionHtml!: string | undefined | null

/**
* Total attests with value True
*/
Expand Down

0 comments on commit 763879e

Please sign in to comment.