Skip to content

Commit

Permalink
use old path
Browse files Browse the repository at this point in the history
  • Loading branch information
EndangeredMassa committed Sep 30, 2023
1 parent 0fc1212 commit f81e3b6
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 11 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
## To Do

- clean up styling
- add redirects for old slug to new slug
- 404 protection: https://remysharp.com/2023/09/26/no-more-404
- add search: https://pagefind.app/
2 changes: 1 addition & 1 deletion app/components/article-card.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LinkTo } from '@ember/routing';
<template>
<div class="blog-item">
<LinkTo class="post-link"
@route='article'
@route="article"
@model={{@article}}>
{{@article.title}}
</LinkTo>
Expand Down
4 changes: 2 additions & 2 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Router.map(function () {
this.route('index', { path: '/' });
})

this.route('articles', function() {
this.route('blog', function() {
this.route('index', { path: '/' });
});

this.route('article', { path: '/articles/:slug' });
this.route('article', { path: '/blog/:slug' });
});
12 changes: 8 additions & 4 deletions app/routes/article.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import Route from '@ember/routing/route';
import articles from '../article-data';

export default class ArticlesArticleRoute extends Route {
export default class BlogRoute extends Route {
beforeModel(transition) {
// set the proper template

let slug;
if (transition.intent.url) {
// direct load
slug = transition.intent.url.replace('/articles/', '');
slug = transition.intent.url.replace('/blog/', '');
} else {
// linked load
slug = transition.routeInfos[1].context.slug;
const info = transition.routeInfos[1];

slug = info?.context?.slug || info?.params?.slug;
}

this.templateName = `articles.${slug}`;
if (slug) {
this.templateName = `article.${slug}`;
}
}

model(params) {
Expand Down
2 changes: 1 addition & 1 deletion app/templates/application.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MyRouteComponent extends Component {
<header>
<nav>
<LinkTo @route="index">Home</LinkTo>
<LinkTo @route="articles">Articles</LinkTo>
<LinkTo @route="blog">Blog</LinkTo>
<LinkTo @route="talks">Talks</LinkTo>
<LinkTo @route="projects">Projects</LinkTo>
</nav>
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/scan-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ module.exports = async function ({ distDir, visit }) {
.replace('export default articles;', '');
let articles = JSON.parse(trimmedArticleData);
let articleUrls = articles.map((a) => {
return '/articles/' + a.slug.replace(/\./g, '/');
return '/blog/' + a.slug.replace(/\./g, '/');
});

return [
'/',
'/talks',
'/articles',
'/blog',
'/projects',
...articleUrls
];
Expand Down

0 comments on commit f81e3b6

Please sign in to comment.