think I found the write file for the js.

This commit is contained in:
Jonathan Snyder 2024-11-17 15:32:46 -05:00
parent 37b61681f2
commit db6694a612
No known key found for this signature in database
GPG key ID: 307FA2726BCF24CF
2 changed files with 43 additions and 47 deletions

View file

@ -14,6 +14,48 @@
{{if not .IsPrivate}}<link rel="alternate" type="application/rss+xml" title="{{.DisplayTitle}} &raquo; Feed" href="{{.CanonicalURL}}feed/" />{{end}}
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script>
(function() {
// Function to convert URL to the desired format
function convertUrl(url) {
// Remove the protocol (http:// or https://)
const urlWithoutProtocol = url.replace(/^https?:\/\//, '');
// Split the URL by '/'
const parts = urlWithoutProtocol.split("/");
// Get the last part, which contains the username prefixed with '@'
const usernameWithAt = parts[parts.length - 1];
// Extract the username by removing the '@'
const username = usernameWithAt.substring(1);
// Get the base URL (everything before the username)
const baseUrl = parts.slice(0, parts.length - 1).join("/");
// Log the username and baseUrl to the console for debugging
console.log("Username:", username);
console.log("Base URL:", baseUrl);
// Return the formatted URL in the desired format "@username@baseUrl"
return `@${username}@${baseUrl}`;
}
// URL to be converted
const url = "https://social.vivaldi.net/@ItWasntMe223";
// Convert the URL
const convertedUrl = convertUrl(url);
// Log the converted URL to the console
console.log("Converted URL:", convertedUrl);
// Use document.write to output the result directly
document.write('<meta name="fediverse:creator" content="' + convertedUrl + '" />');
})();
</script>
<meta name="generator" content="WriteFreely">
<meta name="description" content="{{.Description}}">
<meta itemprop="name" content="{{.DisplayTitle}}">

View file

@ -3,55 +3,9 @@
{{if .Monetization -}}
<meta name="monetization" content="{{.DisplayMonetization}}" />
{{- end}}
{{if .Verification -}}
<meta name="fediverse:creator" content="{{.Verification}}">
<link rel="me" href="{{.Verification}}" />
<script>
document.addEventListener('DOMContentLoaded', function () {
// Function to convert URL into the desired format
function convertUrl(url) {
// Remove 'https://' or 'http://' from the beginning of the URL
const cleanUrl = url.replace(/^https?:\/\//, "");
// Split the cleaned URL by "/"
const parts = cleanUrl.split("/");
// Extract the username with @ (last part of the URL)
const usernameWithAt = parts[parts.length - 1];
const username = usernameWithAt.substring(1); // Remove the "@"
// Get the base URL without the username part
const baseUrl = parts.slice(0, parts.length - 1).join("/");
// Return the formatted result like "@username@baseurl"
const result = `@${username}@${baseUrl}`;
return result;
}
// Example URL
const url = "{{.Verification}}";
// Call the function and store the result in a variable
const convertedUrl = convertUrl(url);
// Log the result to confirm the URL is being processed correctly
console.log("Converted URL:", convertedUrl);
// Create a new meta tag
const metaTag = document.createElement('meta');
metaTag.setAttribute('name', 'fediverse:creator');
metaTag.setAttribute('content', convertedUrl);
// Append the new meta tag to the <head> section
document.head.appendChild(metaTag);
// Log to confirm that the meta tag has been added
console.log("Meta tag created and added with content:", metaTag.getAttribute('content'));
});
</script>
{{- end}}
{{end}}