Skip to content

Commit

Permalink
Do both startsWith and endsWith
Browse files Browse the repository at this point in the history
  • Loading branch information
dreeves committed Aug 17, 2023
1 parent 2749194 commit d3691fa
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/pages/404.astro
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,22 @@ function levenshtein(a, b) {
}

const sadslug = location.pathname.slice(1); // the thing that's 404ing
const links = posts.filter(p => p.slug.startsWith(sadslug));
const links1 = posts.filter(p => p.slug.startsWith(sadslug));
const links2 = posts.filter(p => p.slug.endsWith(sadslug));
const ul = document.querySelector("#nearmisses");

ul.appendChild(document.createElement('li')).innerHTML =
`<code>blog.beeminder.com/${sadslug}</code> &nbsp; &mdash; &nbsp; ` +
`what you typed or clicked on`;

for (const l of links) {
for (const l of links1.concat(links2)) {
ul.appendChild(document.createElement('li')).innerHTML =
`<a href="${l.slug}" title="${l.excerpt}">` +
`<code>blog.beeminder.com/${l.slug}</code>` +
`</a> &nbsp; &mdash; &nbsp; ${l.title}`;
}

if (links.length === 0) {
if (links1.length === 0 && links2.length === 0) {
// Find the post with the closest slug to the sad one that's 404'ing
let cpost = '';
let edist = Infinity; // minimum edit distance across all slugs in the archive
Expand Down

0 comments on commit d3691fa

Please sign in to comment.