Skip to content

Commit

Permalink
Now storing theme in localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
nobleknightt committed Jun 2, 2024
1 parent f90ca00 commit 2a66d30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@
},
];
let themeIndex = 0;
let themeIndex = parseInt(localStorage.getItem("BLOGS_THEME_INDEX")) || Math.floor(Math.random() * themes.length);
localStorage.setItem("BLOGS_THEME_INDEX", themeIndex.toString());
$: theme = themes[themeIndex];
function changeTheme() {
themeIndex = (themeIndex + 1) % themes.length;
localStorage.setItem("BLOGS_THEME_INDEX", themeIndex.toString());
}
</script>

Expand All @@ -181,7 +184,7 @@
<li
class="p-2 flex flex-col gap-2 {theme.backgroundColor_Card} rounded-lg"
>
<a href={blog.url} class="text-2xl font-medium flex-1">{blog.name}</a>
<a href={blog.url} class="text-2xl font-medium flex-1" target="_blank">{blog.name}</a>
<ul class="flex flex-wrap gap-2">
{#each blog.tags as tag}
<span class="{theme.backgroundColor_Tag} rounded-md px-2"
Expand Down
5 changes: 5 additions & 0 deletions src/blogs.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@
"name": "Shawn Wang's Blog",
"url": "https://www.swyx.io/",
"tags": ["Software Engineering", "Career"]
},
{
"name": "Phil Eaton's Blog",
"url": "https://eatonphil.com/",
"tags": ["Software Development"]
}
]

0 comments on commit 2a66d30

Please sign in to comment.