-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🎉 Add related research and writing via content graph to data pages #2739
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
15e1c46
:construction: start drafting new table
danyx23 365a41d
:constrution: tweak full posts link generation, almost complete
danyx23 d681df2
:sparkles: add updating of PostLink to wp update hook
danyx23 a80c490
:construction: WIP - query for related research and writing
danyx23 8d4b75e
:bug: fix group by
danyx23 63a9737
:tada: start showing related research and writing
danyx23 b8f28fd
:hammer: add temporary thumbnail rendering
danyx23 5204cf5
:bug: fix wordpress authors display
danyx23 6480d6f
:hammer: tweak related research query
danyx23 6cd3a2d
🤖 style: prettify code
danyx23 e9738a9
:honeybee: fix lint issues
danyx23 50c0f71
:hammer: add tooling to get pageview data into local mysql
danyx23 f7a695c
:hammer: make sure pageviews as 0 and not null
danyx23 7ab6aaf
:sparkles: use thumbnails for wp posts
danyx23 b726d7f
:hammer: add tags to content that is retrieved
danyx23 156daeb
: hammer: incorporate tags when matching related research
danyx23 a8e8f74
:honeybee: fix accidental commits in launch.json
danyx23 796f8c4
:hammer: fix filter query
danyx23 f640483
:hammer: fix page title fallback to chart tile
danyx23 99dc5ba
:bug: fix url not showing up in citation
danyx23 be2a07f
:hammer: hide charts thumbnails in all charts block for single charts
danyx23 a07aa34
:hammer: hard code link redirects from country templates to selector
danyx23 78c20b5
Simplify find postlink
danyx23 b617889
🔨incorporate feedback
danyx23 2943fbe
:lipstick: (lint) remove unused variable
sophiamersmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ wordpress/web/wp/wp-content/** | |
wordpress/vendor/** | ||
packages/@ourworldindata/*/dist/ | ||
dist/ | ||
.vscode/ |
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 { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class AddPostsLinks1692042923850 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
queryRunner.query(`-- sql | ||
CREATE TABLE posts_links ( | ||
id int NOT NULL AUTO_INCREMENT, | ||
sourceId int NOT NULL, | ||
target varchar(2047) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs NOT NULL, | ||
linkType enum('url','grapher','explorer', 'gdoc') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs DEFAULT NULL, | ||
componentType varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs NOT NULL, | ||
text varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs NOT NULL, | ||
queryString varchar(2047) COLLATE utf8mb4_0900_as_cs NOT NULL, | ||
hash varchar(2047) COLLATE utf8mb4_0900_as_cs NOT NULL, | ||
PRIMARY KEY (id), | ||
KEY sourceId (sourceId), | ||
CONSTRAINT posts_links_ibfk_1 FOREIGN KEY (sourceId) REFERENCES posts (id) | ||
) ENGINE=InnoDB;`) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
queryRunner.query(`-- sql | ||
DROP TABLE IF EXISTS posts_links; | ||
`) | ||
} | ||
} |
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,47 @@ | ||
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm" | ||
import { formatUrls } from "../../site/formatting.js" | ||
import { Url } from "@ourworldindata/utils" | ||
import { getLinkType, getUrlTarget } from "@ourworldindata/components" | ||
|
||
@Entity("posts_links") | ||
export class PostLink extends BaseEntity { | ||
@PrimaryGeneratedColumn() id!: number | ||
// TODO: posts is not a TypeORM but a Knex class so we can't use a TypeORM relationship here yet | ||
|
||
@Column({ type: "int", nullable: false }) sourceId!: number | ||
|
||
@Column() linkType!: "gdoc" | "url" | "grapher" | "explorer" | ||
@Column() target!: string | ||
@Column() queryString!: string | ||
@Column() hash!: string | ||
@Column() componentType!: string | ||
@Column() text!: string | ||
|
||
static createFromUrl({ | ||
url, | ||
sourceId, | ||
text = "", | ||
componentType = "", | ||
}: { | ||
url: string | ||
sourceId: number | ||
text?: string | ||
componentType?: string | ||
marcelgerber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}): PostLink { | ||
const formattedUrl = formatUrls(url) | ||
const urlObject = Url.fromURL(formattedUrl) | ||
const linkType = getLinkType(formattedUrl) | ||
const target = getUrlTarget(formattedUrl) | ||
const queryString = urlObject.queryStr | ||
const hash = urlObject.hash | ||
return PostLink.create({ | ||
target, | ||
linkType, | ||
queryString, | ||
hash, | ||
sourceId, | ||
text, | ||
componentType, | ||
}) | ||
} | ||
} |
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,49 @@ | ||
// index.ts | ||
import fetch from "node-fetch" | ||
import Papa from "papaparse" | ||
import * as db from "./db.js" | ||
|
||
async function downloadAndInsertCSV(): Promise<void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! 🙌 |
||
const csvUrl = "http://datasette-private/owid/pageviews.csv?_size=max" | ||
const response = await fetch(csvUrl) | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
`Failed to fetch CSV: ${response.statusText} from ${csvUrl}` | ||
) | ||
} | ||
|
||
const csvText = await response.text() | ||
const parsedData = Papa.parse(csvText, { | ||
header: true, | ||
}) | ||
|
||
if (parsedData.errors.length > 1) { | ||
console.error("Errors while parsing CSV:", parsedData.errors) | ||
return | ||
} | ||
|
||
const onlyValidRows = [...parsedData.data].filter( | ||
(row) => Object.keys(row as any).length === 5 | ||
) as any[] | ||
|
||
console.log("Parsed CSV data:", onlyValidRows.length, "rows") | ||
console.log("Columns:", parsedData.meta.fields) | ||
|
||
await db.knexRaw("TRUNCATE TABLE pageviews") | ||
|
||
await db.knexInstance().batchInsert("pageviews", onlyValidRows) | ||
console.log("CSV data inserted successfully!") | ||
} | ||
|
||
const main = async (): Promise<void> => { | ||
try { | ||
await downloadAndInsertCSV() | ||
} catch (e) { | ||
console.error(e) | ||
} finally { | ||
await db.closeTypeOrmAndKnexConnections() | ||
} | ||
} | ||
|
||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tragedy of alphabetization 🥲