Skip to content

Commit 4b9ea6b

Browse files
committed
fixed blog language change
1 parent 6f4fb91 commit 4b9ea6b

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

src/components/Header.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const t = useTranslations(lang);
2222
<p class="uppercase text-3xl text-zinc-900">blog</p>
2323
</a>
2424
<ul class="flex gap-x-8">
25-
<li><a href="/" class="text-teal-900 font-bold">{t('nav.home')}</a></li>
25+
<li><a href={`/${lang}/`} class="text-teal-900 font-bold">{t('nav.home')}</a></li>
2626
<li><a href={`/${lang}/about`} class="text-teal-900 font-bold">{t('nav.about')}</a></li>
2727
<li><a href={`/${lang}/blog`} class="text-teal-900 font-bold">Blog</a></li>
2828
<li><ThemeDropdown name="theme"></ThemeDropdown></li>
Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
11
---
22
import { languages } from '../i18n/ui';
33
import { getLangFromUrl } from '../i18n/utils';
4+
import blog from "../data/blog.json";
45
5-
function getPath(){
6+
function getIndex(aux: string, lang: string){
7+
var filteredObj = blog.find(function(item, i){
8+
if(lang == 'en'){
9+
if(item.en === aux){
10+
return i;
11+
}
12+
}
13+
else{
14+
if(item.ptbr === aux){
15+
return i;
16+
}
17+
}
18+
});
19+
return 0;
20+
}
21+
22+
function getPath(lang_org: string){
623
let lang = getLangFromUrl(Astro.url);
24+
var url = Astro.url.pathname.split( '/' );
25+
var title = '';
26+
console.log(url)
27+
console.log(blog[0].en)
28+
if(url.length > 3 && (url[2] == 'blog' || url[2] == 'portfolio')){
29+
var aux = url[3];
30+
if(lang_org == 'en'){
31+
var i = getIndex(aux, lang);
32+
title = blog[i].en
33+
}else{
34+
var i = getIndex(aux, lang);
35+
title = blog[i].ptbr
36+
}
37+
console.log("oiii");
38+
var string = Astro.url.pathname;
39+
console.log(string);
40+
string = string.replace(`/${lang}/`, '');
41+
console.log(string);
42+
string = string.replace(`/${url[3]}`, `/${title}`);
43+
console.log(string);
44+
return string;
45+
}
746
return Astro.url.pathname.replace(`/${lang}/`, '');
847
}
948
1049
---
1150
<ul>
1251
{Object.entries(languages).map(([lang, label]) => (
1352
<li>
14-
<a href={`/${lang}/${getPath()}`}>{label}</a>
53+
<a href={`/${lang}/${getPath(lang)}`}>{label}</a>
1554
</li>
1655
))}
1756
</ul>

src/data/blog.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"en": "hello.mdx",
4+
"ptbr": "ola.mdx"
5+
}
6+
]

0 commit comments

Comments
 (0)