CV1

Check out the latest posts
You’ve successfully subscribed to Matt Rutherford 👓
Welcome back! You’ve successfully signed in.
Great! You’ve successfully signed up.
Success! Your email is updated.
Your link has expired
Success! Check your email for magic link to sign-in.
Please enter at least 3 characters 0 Results for your search
// 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

`; }); }