Sign In

Processing your application There was an error sending the email
Don’t have an account yet? Sign up

Great!

Please check your inbox and click the link to complete signin.

Back to homepage
// Ghost Latest Tag Redirect - Code Injection Solution // This code redirects to the latest post with a specific tag // The mapping between URL paths and tag slugs const pathToTagMap = { '/weeknote': 'weeknote', '/newsletter': 'newsletter' // Add more paths as needed }; // Only run the script if we're on one of the mapped paths const currentPath = window.location.pathname; const tagSlug = pathToTagMap[currentPath] || pathToTagMap[currentPath + '/']; if (tagSlug) { // Show a loading message document.body.innerHTML = '

Loading latest ' + tagSlug + '...

'; // Fetch the latest post with the specified tag fetch(`/ghost/api/content/posts/?key=533db792a70d450ac8dcae8dff&filter=tag:${tagSlug}&limit=1&order=published_at%20desc&fields=url,title,published_at`) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { if (data.posts && data.posts.length > 0) { // Redirect to the post window.location.href = data.posts[0].url; } else { // Show a message if no posts are found document.body.innerHTML = `

No ${tagSlug}s found

There don't seem to be any posts with the '${tagSlug}' tag yet.

Return to homepage

`; } }) .catch(error => { console.error('Error fetching posts:', error); document.body.innerHTML = `

Something went wrong

Unable to fetch the latest ${tagSlug}. Please try again later.

Return to homepage

`; }); }