Merge pull request #1443 from Hans5958/live-love-life/5

Various "minor" changes (5)
This commit is contained in:
Stefano 2023-06-22 13:23:10 +02:00 committed by GitHub
commit 02e6942722
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 33 deletions

View file

@ -28,7 +28,9 @@ Once you've entered all the information, you'll be presented with a pop-up windo
### Through Reddit
You can press the <kbd>Post Direct to Reddit</kbd> button and just press the send button on Reddit, or copy the entire JSON text and [create a new text post on the subreddit](https://www.reddit.com/r/placeAtlas2/submit). You don't need to add any other text; just directly send the data.
You can press the <kbd>Post Direct to Reddit</kbd> button, which will open a page with the title and body already been filled for you. You don't need to change anything what has been prepared.
If that didn't work, copy the entire JSON text and [create a new text post on the subreddit](https://www.reddit.com/r/placeAtlas2/submit). You don't need to add any other text; just directly send the data.
Remember to flair your post with <kbd>New Entry</kbd>. On New Reddit, click the <kbd>Flair</kbd> button on the bottom part, and select <kbd>New Entry</kbd>. On Old Reddit, click the <kbd>select</kbd> button on the "choose a flair" section instead.
@ -36,9 +38,11 @@ Remember to flair your post with <kbd>New Entry</kbd>. On New Reddit, click the
If you know about Git and how to create a pull request on GitHub, you can try create a patch that will be merged, along with other patches, by one of the members.
You can use the provided `tools/create_patch.py` script. This script helps you to create a working patch, along with additional data such as your name for attribution sakes. Simply run the script inside the `tools/` folder and follow the given instructions.
You can try pressing the <kbd>Submit Direct to GitHub</kbd> button, which will open a page with the patch file already been prepared to you. If you haven't forked the repository, you would need to fork it with the provided instruction shown on the page. You may add attribution by adding an `_author` key, explained in the next paragraphs. After that, you can press <kbd>Submit changes</kbd>, add follow the steps to create a pull request within GitHub.
If you want to do this manually (e.g. you don't have Python), you can create a patch by creating a `.json` file inside `data/patches`, with the content of the JSON-formatted data that is given earlier. You may add attribution by adding a `_author` key with the value of your Reddit username or your GitHub username plus a `gh:` prefix.
If you can fork and clone the repository, you can use the provided `tools/create_patch.py` script. This script helps you to create a working patch, along with additional data such as your name for attribution sakes. Simply run the script inside the `tools/` folder and follow the given instructions.
If you want to do this manually (e.g. you don't have Python), you can create a patch by creating a `.json` file inside `data/patches`, with the content of the JSON-formatted data that is given earlier. You may add attribution by adding an `_author` key with the value of your Reddit username or your GitHub username plus a `gh:` prefix.
```json5
{

View file

@ -11,6 +11,9 @@ window.instanceId = instanceId
const instanceSubreddit = "placeAtlas2"
window.instanceSubreddit = instanceSubreddit
const instanceRepo = "https://github.com/placeAtlas/atlas"
window.instanceRepo = instanceRepo
const pageTitle = "The 2022 r/place Atlas"
window.pageTitle = pageTitle
@ -251,7 +254,7 @@ window.defaultVariation = defaultVariation
let defaultPeriod = variationsConfig[defaultVariation].default
window.defaultPeriod = defaultPeriod
const useNumericalId = false
const useNumericalId = true
window.useNumericalId = useNumericalId
console.info(`%cThe 2022 r/place Atlas

View file

@ -24,8 +24,10 @@ const periodsAdd = document.getElementById('periodsAdd')
const exportButton = document.getElementById("exportButton")
const cancelButton = document.getElementById("cancelButton")
const exportDirectPostButton = document.getElementById("exportDirectPost")
let exportDirectPostTooltip = null
const redditPostButton = document.getElementById("exportRedditPost")
let redditPostTooltip = null
const githubPostButton = document.getElementById("exportGithubPost")
let githubPostTooltip = null
const exportModalElement = document.getElementById("exportModal")
const exportModal = new bootstrap.Modal(exportModalElement)
@ -86,6 +88,17 @@ baseInputField.type = "text"
})
})
// https://gist.github.com/codeguy/6684588?permalink_comment_id=3243980#gistcomment-3243980
function slugify(text) {
return text
.normalize('NFKD')
.toLowerCase()
.trim()
.replace(/\s+/g, '-')
.replace(/[^\w\-]+/g, '')
.replace(/\-+/g, '-');
}
window.initDraw = initDraw
function initDraw() {
// Adds exit draw button and removes list button
@ -303,43 +316,76 @@ function initDraw() {
return exportObject
}
document.getElementById("exportCopy").addEventListener("click", () => {
navigator.clipboard.writeText(exportArea.value)
})
function exportJson() {
const exportObject = generateExportObject()
const prettyJsonString = JSON.stringify(exportObject, null, "\t")
const miniJsonString = JSON.stringify(exportObject)
let prettyJsonString = JSON.stringify(exportObject, null, "\t")
prettyJsonString = " " + prettyJsonString.split("\n").join("\n ")
exportArea.value = prettyJsonString
let directPostJsonString = prettyJsonString
let directPostUrl = `https://www.reddit.com/r/${instanceSubreddit}/submit?selftext=true&title=`
if (exportObject.id === 0) directPostUrl += `✨%20${encodeURIComponent(exportObject.name)}`
else directPostUrl += `✏%20${encodeURIComponent(exportObject.name)}`
directPostUrl += "&text="
// Export area
if (directPostJsonString.length + directPostJsonString > 7579) {
directPostJsonString = " " + JSON.stringify(exportObject)
}
exportArea.value = " " + prettyJsonString.split("\n").join("\n ")
if (exportArea.value > 40000) {
exportArea.value = " " + JSON.stringify(exportObject)
exportArea.value = " " + miniJsonString
}
directPostUrl += encodeURIComponent(directPostJsonString)
// Reddit
if (directPostUrl.length > 7579) {
// exportDirectPostButton.classList.add("disabled")
// exportDirectPostButton.ariaDisabled = true
exportDirectPostButton.dataset.bsToggle = "tooltip"
exportDirectPostButton.dataset.bsTitle = "This may not work due to the length of the entry. If needed, please copy manually."
if (!exportDirectPostTooltip) exportDirectPostTooltip = new bootstrap.Tooltip(exportDirectPostButton)
} else {
// exportDirectPostButton.classList.remove("disabled")
// exportDirectPostButton.ariaDisabled = false
exportDirectPostButton.dataset.bsTitle = ""
let redditPostJsonString = " " + prettyJsonString.split("\n").join("\n ")
let redditPostUrl = `https://www.reddit.com/r/${instanceSubreddit}/submit?selftext=true&title=`
if (exportObject.id === 0) redditPostUrl += `✨%20${encodeURIComponent(exportObject.name)}`
else redditPostUrl += `✏%20${encodeURIComponent(exportObject.name)}`
redditPostUrl += "&text="
if (encodeURIComponent(redditPostJsonString).length > 7579 - redditPostUrl.length) {
redditPostJsonString = " " + miniJsonString
}
exportDirectPostButton.href = directPostUrl
redditPostUrl += encodeURIComponent(redditPostJsonString)
if (encodeURIComponent(redditPostUrl).length > 7579) {
// redditPostButton.classList.add("disabled")
// redditPostButton.ariaDisabled = true
redditPostButton.dataset.bsToggle = "tooltip"
redditPostButton.dataset.bsTitle = "This may not work due to the length of the entry. If needed, please copy manually."
if (!redditPostTooltip) redditPostTooltip = new bootstrap.Tooltip(redditPostButton)
} else {
// redditPostButton.classList.remove("disabled")
// redditPostButton.ariaDisabled = false
redditPostButton.dataset.bsTitle = ""
}
redditPostButton.href = redditPostUrl
if (exportObject.id === 0) document.getElementById("redditFlair").textContent = "New Entry"
else document.getElementById("redditFlair").textContent = "Edit Entry"
// GitHub
let githubPostJsonString = prettyJsonString
let githubPostUrl = `${instanceRepo}/new/cleanup/data/patches?filename=gh-${[...Array(4)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')}-${slugify(exportObject.name)}.json&value=`
if (encodeURIComponent(githubPostJsonString).length > 8192 - githubPostUrl.length) {
githubPostJsonString = miniJsonString
}
githubPostUrl += encodeURIComponent(githubPostJsonString)
if (githubPostUrl.length > 8192) {
// githubPostButton.classList.add("disabled")
// githubPostButton.ariaDisabled = true
githubPostButton.dataset.bsToggle = "tooltip"
githubPostButton.dataset.bsTitle = "This may not work due to the length of the entry. If needed, please copy manually."
if (!githubPostTooltip) githubPostTooltip = new bootstrap.Tooltip(githubPostButton)
} else {
// githubPostButton.classList.remove("disabled")
// githubPostButton.ariaDisabled = false
githubPostButton.dataset.bsTitle = ""
}
githubPostButton.href = githubPostUrl
console.log(githubPostUrl)
exportModal.show()
}

View file

@ -347,13 +347,17 @@ <h5 class="modal-title" id="exportModalLabel">Export Entry</h5>
<p>
If you want to use Reddit, use the <span class="badge bg-primary">Post Direct to Reddit</span> button or manually copy the text below and submit it as a new text post to <a href="https://www.reddit.com/r/placeAtlas2/" target="_blank" rel="noopener noreferrer">r/placeAtlas2</a> on Reddit.
Don't forget to flair it with the <span class="badge rounded-pill bg-primary"><i class="bi bi-tag" aria-hidden="true"></i> <span id="redditFlair">New Entry</span></span> flair.</p>
<p>If you want to use GitHub, read <a href="https://github.com/placeAtlas/atlas/blob/master/CONTRIBUTING.md#through-github" target="_blank" rel="noopener noreferrer">the contributing guide</a> to submit a patch.</p>
<p>
If you want to use GitHub, use the <span class="badge bg-primary">Submit Direct to GitHub</span> button, or read <a href="https://github.com/placeAtlas/atlas/blob/master/CONTRIBUTING.md#through-github" target="_blank" rel="noopener noreferrer">the contributing guide</a> to submit a patch.
</p>
<p>We will then check it and add it to the Atlas.</p>
<textarea class="form-control flex-grow-1" cols="40" rows="20" id="exportString" title="Raw JSON string" readonly></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button>
<a id="exportDirectPost" class="btn btn-primary" href="#" target="_blank" rel="noopener noreferrer">Post Direct to Reddit</a>
<button id="exportCopy" type="button" class="btn btn-secondary">Copy</button>
<a id="exportGithubPost" class="btn btn-primary" href="#" target="_blank" rel="noopener noreferrer">Submit Direct on GitHub</a>
<a id="exportRedditPost" class="btn btn-primary" href="#" target="_blank" rel="noopener noreferrer">Post Direct on Reddit</a>
</div>
</div>
</div>