-
Notifications
You must be signed in to change notification settings - Fork 12
add prompt functionality (in progress) #62
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
base: main
Are you sure you want to change the base?
Conversation
…wn prompt claimers. Squished bugs this created
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.
Thank you so much for the excellent work, please let me know if any of the comments are unclear.
@@ -34,6 +34,7 @@ | |||
"scripts": { | |||
"build": "rm -rf dist/ && tsup src/index.ts src/urls.ts --format esm,cjs --dts", | |||
"test": "NODE_OPTIONS=--experimental-vm-modules jest --no-cache .test.ts$ --verbose=true", | |||
"test-prompts": "NODE_OPTIONS=--experimental-vm-modules jest --no-cache prompts.test.ts$ --verbose=true", |
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.
Please revert this change, we'll add documentation on how to do it without needing to add a new script.
relationships: getPromptRelationships(promptPage), | ||
additional: getPromptAdditionalTags(promptPage) | ||
}, | ||
//TODO: |
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.
Fill or delete this TODO
|
||
|
||
export const getPromptDetailsFromUrl = ({ | ||
// defining the input structure, eg. |
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.
This might work better as a single function-level comment. You could write it as:
/**
* Extracts promptId and collectionName from the URL of a collection.
*
* For example, given the url "https://archiveofourown.org/collections/mo_dao_zu_shi_kink_meme_2020/prompts/2644428"
* this function will return:
* - promptId: 2644428
* - collectionName: mo_dao_zu_shi_kink_meme_2020
**/
export const getPromptDetailsFromUrl = ({ url,
}: {
url: string;
}): {
promptId: string;
collectionName: string
} => {
promptId: string; | ||
collectionName: string | ||
} => { | ||
const promptUrlMatch = url.match(/prompts\/(\d+)/); |
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.
You might want to merge these in a single regex test, something like:
const collectionUrlMatch = url.match(/collections\/(\w+)/prompts\/(\d+)/);
if (!collectionUrlMatch) {
throw new Error("Invalid prompt URL");
}
return {
promptId: collectionUrlMatch[2],
collectionName: collectionUrlMatch[1]
};
Double-check that I'm extracting the groups correctly, cause I always forget the syntax.
promptId: string, | ||
collectionName:string | ||
})=>{ | ||
let workUrl = `https://archiveofourown.org`; |
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.
You can do this with a single return statement like
return `https://archiveofourown.org/collections/${collectionName}/prompts/${promptId}`
|
||
describe("Fetches prompt information", () => { | ||
|
||
test("Fetches prompt published date", async () => { |
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.
"published date and summary"
}); | ||
}); | ||
|
||
test("Fetches Prompt Categores (single)", async () => { |
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.
s/categores/categories
}); | ||
|
||
|
||
//WIP PROMPTS |
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.
Remove the comment
|
||
}); | ||
|
||
|
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.
Suggestion: i think this file is getting long so it might be worth considering splitting it in multiple files
collectionName: "mo_dao_zu_shi_kink_meme_2020", | ||
id: "1909048", | ||
filled: true, | ||
// fills: [ |
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.
If these are commented out for a reason, write a comment about why, if not either uncomment or delete.
@@ -34,6 +34,7 @@ | |||
"scripts": { | |||
"build": "rm -rf dist/ && tsup src/index.ts src/urls.ts --format esm,cjs --dts", | |||
"test": "NODE_OPTIONS=--experimental-vm-modules jest --no-cache .test.ts$ --verbose=true", | |||
"test-prompts": "NODE_OPTIONS=--experimental-vm-modules jest --no-cache prompts.test.ts$ --verbose=true", |
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.
I believe the way to do this should be:
npm run test -- prompts.test.ts$
This adds (incomplete) functionality to scrape data from /collections/{collection name}/prompts/{prompt id}
eg. /collections/test_prompt_meme_2024/prompts/3566161
I mostly copied the existing code, I hope it worked out!
Includes:
Does not (yet) include:
Issues