Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

Commit 7e112fa

Browse files
committed
chore(publishing): improve XenForo formatting
1 parent 8d9251d commit 7e112fa

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

publish.ps1

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,7 @@ function Update-TShockResource($releaseVersion, $terrariaVersion, $pluginApiVers
247247
$fields["version_string"] = $releaseVersion
248248

249249
$readmeMarkdown = Get-Content $readmeFile
250-
$readmeMarkdown = ($readmeMarkdown -join "`n")
251-
$readmeMarkdown = $readmeMarkdown -replace "<","&lt;"
252-
$readmeMarkdown = $readmeMarkdown -replace ">","&gt;"
253-
$readmeHtml = ConvertFrom-Markdown -MarkdownContent ($readmeMarkdown -join "`n")
254-
# make things a bit prettier because XenForo does some weird transformations to the html
255-
$readmeHtml = $readmeHtml -replace "<h3>","<br><h3>"
256-
$readmeHtml = $readmeHtml -replace "</p>[\s\n\r]*<p>","<br><br>"
257-
$fields["message_html"] = $readmeHtml
250+
$fields["message_html"] = Convert-MarkdownToHtml $readmeMarkdown
258251

259252
# save the resource
260253
$response = Invoke-WebRequest -Uri "$tshockResourceUri/save" -Method Post -Body $fields -WebSession $session
@@ -267,21 +260,34 @@ function Update-TShockResource($releaseVersion, $terrariaVersion, $pluginApiVers
267260
$fields["download-url"] = "https://github.com/$gitHubUser/$gitHubRepoName/releases/tag/$releaseVersion"
268261
$fields["version-string"] = $releaseVersion
269262
$fields["title"] = "$releaseVersion Update"
270-
$fields["message_html"] = "$releaseVersion Update"
271263

272264
$changelogMarkdown = Get-Content $changelogFile
273265
# remove commit hashes
274266
$changelogMarkdown = $changelogMarkdown -replace "\(\[[A-Za-z0-9]+\]\([A-Za-z0-9]+\)\)",""
275-
276-
$changelogHtml = ConvertFrom-Markdown -MarkdownContent ($changelogMarkdown -join "`n")
277-
# make things a bit prettier because XenForo does some weird transformations to the html
278-
$changelogHtml = $changelogHtml -replace "<h4>","<br><h4>"
279-
$fields["message_html"] = $changelogHtml
267+
$fields["message_html"] = Convert-MarkdownToHtml $changelogMarkdown
280268

281269
# post update
282270
$response = Invoke-WebRequest -Uri "$tshockResourceUri/save-version" -Method Post -Body $fields -WebSession $session
283271
}
284272

273+
function Convert-MarkdownToHtml($markdown) {
274+
$html = ConvertFrom-Markdown -MarkdownContent ($markdown -join "`n")
275+
276+
# make things a bit prettier because XenForo does some weird transformations to the html
277+
$html = $html -replace '<p><a name=".*"></a></p>[\s\n\r]*',""
278+
$html = $html -replace "</p>[\s\n\r]*<p>","<br><br>"
279+
$html = $html -replace "<h3>","<br><h3>"
280+
$html = $html -replace '<p><a name=".*"></a></p>[\s\n\r]*',""
281+
$html = $html -replace "<h4>","<br><h4>"
282+
$html = $html -replace "<h2>(.*)</h2>",'<span style="font-size: 18px"><b>$1</b></span><br>'
283+
$html = $html -replace "<h3>(.*)</h3>",'<span style="font-size: 15px"><b>$1</b></span><br>'
284+
$html = $html -replace "<h4>(.*)</h4>",'<span style="font-size: 14px"><b>$1</b></span><br>'
285+
$html = $html -replace "</h2>[\s\n\r]*<br>","</h2><br>"
286+
$html = $html -replace "</span><br>[\s\n\r]*<p>","</span><br><br><p>"
287+
288+
return $html
289+
}
290+
285291
function Construct-FormFields($request, $formHtmlElement) {
286292
$fields = @{}
287293
$inputFields = $formHtmlElement.getElementsByTagName("input") | Where { $_.name -and $_.type -ne "button" }

0 commit comments

Comments
 (0)