Created
June 10, 2023 19:23
-
-
Save mark05e/c8de42c387d0ee9639ebd715e9f3c10c to your computer and use it in GitHub Desktop.
Powershell script to insert js and css contents into an html
This file contains hidden or 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
# Define the HTML file path | |
$htmlFilePath = "main-template.html" | |
# Define the CSS file path | |
$cssFilePath = "style.css" | |
# Define the JS file path | |
$jsFilePath = "functions.js" | |
# Define the output file path | |
$outputFilePath = "main.html" | |
# Read the CSS file content | |
$cssContent = Get-Content -Path $cssFilePath -Raw | |
# Read the JS file content | |
$jsContent = Get-Content -Path $jsFilePath -Raw | |
# Read the HTML file content | |
$htmlContent = Get-Content -Path $htmlFilePath -Raw | |
# Define the CSS start and end tags | |
$cssStartTag = "<!--CSS_START-->" | |
$cssEndTag = "<!--CSS_END-->" | |
# Define the JS start and end tags | |
$jsStartTag = "<!--JS_START-->" | |
$jsEndTag = "<!--JS_END-->" | |
# Replace the CSS content in the HTML file | |
$cssReplacement = "$cssStartTag`n<style>`n$cssContent`n</style>`n$cssEndTag" | |
$htmlContent = $htmlContent -replace "(?s)$cssStartTag.*?$cssEndTag", $cssReplacement | |
# Replace the JS content in the HTML file | |
$jsReplacement = "$jsStartTag`n<script>`n$jsContent`n</script>`n$jsEndTag" | |
$htmlContent = $htmlContent -replace "(?s)$jsStartTag.*?$jsEndTag", $jsReplacement | |
# Save the modified HTML content to the output file | |
$htmlContent | Set-Content -Path $outputFilePath |
This file contains hidden or 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
// js functions |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Simple HTML Page</title> | |
<!--CSS_START--> | |
<style><!--CSS_CONTENT--></style> | |
<!--CSS_END--> | |
</head> | |
<body> | |
<h1>Hello, World!</h1> | |
<!--JS_START--> | |
<script><!--JS_CONTENT--></script> | |
<!--JS_END--> | |
</body> | |
</html> |
This file contains hidden or 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
// css style |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment