Skip to content
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

Made links configurable #1795

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/read-ids.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7188,3 +7188,4 @@
1dps0t4
1e24aqx
1e3ql1b
1e5p1d3
86 changes: 86 additions & 0 deletions web/_js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,92 @@ window.defaultPeriod = defaultPeriod
const useNumericalId = true
window.useNumericalId = useNumericalId

const externalLinksConfig = [
{
name: "Website",
id: "website",
generateLink: (link) => link,
listingClass: "bi-globe",
generateListingName: (link) => {
try {
const urlObject = new URL(link)
return urlObject.hostname.replace(/^www./, "")
} catch (e) {
return "Website"
}
},
displayHTML: "{urlid}",
placeholder: "https://example.org",
configureInputField: (inputField) => {
inputField.type = "url"
inputField.placeholder = "https://example.com"
inputField.pattern = "https?://.*"
inputField.title = "Website URL using the http:// or https:// protocol"
}
},
{
name: "Discord",
id: "discord",
generateLink: (link) => "https://discord.gg/" + link,
generateListingName: (link) => link,
listingClass: "bi-discord",
editorPrefix: "discord.gg/",
placeholder: "r/example",
configureInputField: (inputField) => {
inputField.placeholder = "pJkm23b2nA"
},
extractId: (content) => {
const discordPattern = /^(?:(?:https?:\/\/)?(?:www\.)?(?:(?:discord)?\.?gg|discord(?:app)?\.com\/invite)\/)?([^\s/]+?)(?=\b)$/
id = content.trim().match(discordPattern)?.[1]
if (id) {
return id;
}
return content;
}
},
{
name: "Subreddit",
id: "subreddit",
generateLink: (link) => "https://reddit.com/" + link,
listingClass: "bi-reddit",
generateListingName: (link) => "r/" + link,
editorPrefix: "reddit.com/",
placeholder: "pJkm23b2nA",
configureInputField: (inputField) => {
inputField.placeholder = "r/example"
inputField.pattern = "^r\/[A-Za-z0-9][A-Za-z0-9_]{1,50}$"
inputField.title = "Subreddit in format of r/example"
inputField.minLength = "4"
inputField.maxLength = "50"
},
extractId: (content) => {
const subredditPattern = /^(?:(?:(?:(?:(?:https?:\/\/)?(?:(?:www|old|new|np)\.)?)?reddit\.com)?\/)?[rR]\/)?([A-Za-z0-9][A-Za-z0-9_]{1,20})(?:\/[^" ]*)*$/
id = content.trim().match(subredditPattern)?.[1]
if (id) {
return id;
}
return content;
},
formatIdInEditor: (content) => {
if (content != "") {
return "r/" + content;
}
return "";
}
},
{
name: "Wiki",
id: "wiki",
generateLink: (link) => "https://place-wiki.stefanocoding.me/wiki/" + link,
listingClass: "bi-wiki",
generateListingName: () => "r/place Wiki Article",
displayHTML: "{urlid}",
placeholder: "r/place Wiki Article",
configureInputField: () => {},
hideInput: true
},
];

console.info(`%cThe 2023 r/place Atlas
%cCopyright (c) 2017 Roland Rytz <[email protected]>
Copyright (c) 2023 Place Atlas Initiative and contributors
Expand Down
Loading