Skip to content

Commit

Permalink
feat: upgrade to tailwind (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
deer authored Dec 17, 2023
1 parent b280497 commit 4bbd906
Show file tree
Hide file tree
Showing 48 changed files with 306 additions and 219 deletions.
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"ok": "deno fmt --check && deno lint && deno task check:types && deno task test"
},
"imports": {
"$fresh/": "https://deno.land/x/[email protected]/",
"$fresh/": "https://deno.land/x/[email protected]/",
"tailwindcss": "npm:[email protected]",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
Expand Down
6 changes: 3 additions & 3 deletions src/components/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export default function Pagination(
const nextPage = page < totalPages ? page + 1 : null;

return (
<nav className="flex justify-between">
<nav class="flex justify-between">
{prevPage
? (
<a
id="previous-page"
href={`?page=${prevPage}`}
className="hover:underline"
class="hover:underline"
>
{localization.previousPage}
</a>
Expand All @@ -30,7 +30,7 @@ export default function Pagination(
<a
id="next-page"
href={`?page=${nextPage}`}
className="hover:underline"
class="hover:underline"
>
{localization.nextPage}
</a>
Expand Down
4 changes: 2 additions & 2 deletions src/components/PostSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export default function PostSummary(
) {
const { post, showExcerpt } = props;
return (
<div class="py-4 border(t gray-200)" id={`post:${post.slug}`}>
<div class="py-4 border-t border-gray-200" id={`post:${post.slug}`}>
<a class="sm:col-span-2" href={`/blog/${post.slug}`}>
<h3 class="text(3xl gray-900) font-bold">
<h3 class="text-3xl text-gray-900 font-bold">
{post.title}
</h3>
</a>
Expand Down
6 changes: 3 additions & 3 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const blogOptions: BlogOptions = {
);
} else {
configContent = configContent.replace(
`plugins: [twindPlugin(twindConfig)],`,
`plugins: [twindPlugin(twindConfig), ${pluginCode}],`,
`plugins: [tailwind()],`,
`plugins: [tailwind(), ${pluginCode}],`,
);
}

Expand Down Expand Up @@ -89,7 +89,7 @@ async function modifyDenoJson() {
return;
}

denoJson.imports["$fresh/"] = "https://deno.land/x/[email protected].0/";
denoJson.imports["$fresh/"] = "https://deno.land/x/[email protected].1/";

const denoJsonContent = JSON.stringify(denoJson, null, 2) + "\n";
await Deno.writeTextFile(DENO_JSON_PATH, denoJsonContent);
Expand Down
36 changes: 24 additions & 12 deletions src/islands/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,50 @@ export default function NavigationBar(
onClick={() => isOpen.value = !isOpen.value}
>
<span
class={`block h-1 w-6 bg-black ${
isOpen.value ? "transform rotate-45" : ""
class={`${
isOpen.value
? "block h-1 w-6 bg-black transform rotate-45"
: "block h-1 w-6 bg-black"
}`}
>
</span>
<span
class={`block h-1 w-6 bg-black my-1 ${
isOpen.value ? "opacity-0" : ""
class={`${
isOpen.value
? "block h-1 w-6 bg-black my-1 opacity-0"
: "block h-1 w-6 bg-black my-1"
}`}
>
</span>
<span
class={`block h-1 w-6 bg-black ${
isOpen.value ? "transform -rotate-45" : ""
class={`${
isOpen.value
? "block h-1 w-6 bg-black transform -rotate-45"
: "block h-1 w-6 bg-black"
}`}
>
</span>
</label>
<nav
class={`w-full fixed top-0 left-0 overflow-hidden transition-max-height duration-500 lg:relative ${
isOpen.value ? "max-h-screen bg-gray-300" : "max-h-0 lg:max-h-full"
class={`${
isOpen.value
? "w-full fixed top-0 left-0 overflow-hidden transition-max-height duration-500 lg:relative max-h-screen bg-gray-300"
: "w-full fixed top-0 left-0 overflow-hidden transition-max-height duration-500 lg:relative max-h-0 lg:max-h-full"
}`}
>
<ul class="flex flex-col lg:flex-row justify-center items-center gap-4 mx-4 my-6 flex-wrap">
{Object.entries(props.options.navbarItems).map(([key, value]) => (
<li key={key}>
<a
href={value}
class={`p-2 block ${
isHome ? "text-black-900" : "text-black-600"
} hover:underline ${
props.active == value ? "font-bold" : ""
class={`p-2 block hover:underline ${
isHome
? props.active == value
? "text-black-900 font-bold"
: "text-black-900"
: props.active == value
? "text-black-600 font-bold"
: "text-black-600"
}`}
>
{key}
Expand Down
1 change: 1 addition & 0 deletions src/routes/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function AppBuilder(options: BlogOptions) {
return (
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="/styles.css" />
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/archive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createArchivePage(title: string, localization: Localization) {
<title>{title}{localization.archiveTitleEnding}</title>
</Head>
<div>
<div className="flex space-x-2 mb-4">
<div class="flex space-x-2 mb-4">
{allTags.some((x) => x != null) && allTags.map((tag, index) => (
<a
id={`tag-link-${tag}`}
Expand Down
72 changes: 72 additions & 0 deletions src/safelist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
export const safelist = [
"max-w-screen-md",
"px-4",
"pt-16",
"mx-auto",
"pb-16",
"flex",
"justify-between",
"hover:underline",
"mt-8",
"py-4",
"border-t",
"border-gray-200",
"sm:col-span-2",
"text-3xl",
"text-gray-900",
"font-bold",
"text-gray-500",
"mr-1",
"ml-1",
"border",
"border-gray-300",
"py-1",
"px-2",
"rounded",
"inline-block",
"hover:bg-gray-300",
"space-x-2",
"mb-4",
"markdown-body",
"flex-grow",
"sticky",
"top-0",
"w-full",
"z-10",
"items-center",
"text-5xl",
"lg:hidden",
"cursor-pointer",
"z-20",
"block",
"h-1",
"w-6",
"bg-black",
"transform",
"rotate-45",
"my-1",
"opacity-0",
"-rotate-45",
"fixed",
"left-0",
"overflow-hidden",
"transition-max-height",
"duration-500",
"lg:relative",
"max-h-screen",
"bg-gray-300",
"max-h-0",
"lg:max-h-full",
"flex-col",
"lg:flex-row",
"justify-center",
"gap-4",
"mx-4",
"my-6",
"flex-wrap",
"p-2",
"text-black-900",
"text-black-600",
"py-2",
"ml-auto",
];
28 changes: 11 additions & 17 deletions tests/empty_posts_dir_fixture/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@
"lock": false,
"tasks": {
"start": "deno run -A --watch=static/,routes/ dev.ts",
"update": "deno run -A -r https://fresh.deno.dev/update ."
"update": "deno run -A -r https://fresh.deno.dev/update .",
"build": "deno run -A dev.ts build",
"preview": "deno run -A main.ts"
},
"imports": {
"$fresh/": "https://deno.land/x/[email protected].0/",
"$fresh/": "https://deno.land/x/[email protected].1/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"@preact/signals": "https://esm.sh/*@preact/[email protected].2",
"@preact/signals": "https://esm.sh/*@preact/[email protected].1",
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
"twind": "https://esm.sh/[email protected]",
"twind/": "https://esm.sh/[email protected]/",
"tailwindcss": "npm:[email protected]",
"tailwindcss/": "npm:/[email protected]/",
"tailwindcss/plugin": "npm:/[email protected]/plugin.js",
"$std/": "https://deno.land/[email protected]/"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"lint": {
"rules": {
"tags": [
"fresh",
"recommended"
]
}
}
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" },
"lint": { "rules": { "tags": ["fresh", "recommended"] } },
"exclude": ["**/_fresh/*"]
}
5 changes: 2 additions & 3 deletions tests/empty_posts_dir_fixture/fresh.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { defineConfig } from "$fresh/server.ts";
import twind from "$fresh/plugins/twind.ts";
import twindConfig from "./twind.config.ts";
import tailwind from "$fresh/plugins/tailwind.ts";

import { blogPlugin } from "../../src/plugin/blog.ts";
import blogConfig from "./blog.config.ts";

export default defineConfig({
plugins: [twind(twindConfig), blogPlugin(blogConfig)],
plugins: [tailwind(), blogPlugin(blogConfig)],
});
4 changes: 3 additions & 1 deletion tests/empty_posts_dir_fixture/fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.

import { type Manifest } from "$fresh/server.ts";

const manifest = {
routes: {},
islands: {},
baseUrl: import.meta.url,
};
} satisfies Manifest;

export default manifest;
3 changes: 3 additions & 0 deletions tests/empty_posts_dir_fixture/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
9 changes: 9 additions & 0 deletions tests/empty_posts_dir_fixture/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { type Config } from "tailwindcss";
import { safelist } from "../../src/safelist.ts";

export default {
content: [
"{routes,islands,components}/**/*.{ts,tsx}",
],
safelist: safelist,
} satisfies Config;
5 changes: 0 additions & 5 deletions tests/empty_posts_dir_fixture/twind.config.ts

This file was deleted.

28 changes: 11 additions & 17 deletions tests/fixture/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@
"lock": false,
"tasks": {
"start": "deno run -A --watch=static/,routes/ dev.ts",
"update": "deno run -A -r https://fresh.deno.dev/update ."
"update": "deno run -A -r https://fresh.deno.dev/update .",
"build": "deno run -A dev.ts build",
"preview": "deno run -A main.ts"
},
"imports": {
"$fresh/": "https://deno.land/x/[email protected].0/",
"$fresh/": "https://deno.land/x/[email protected].1/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"@preact/signals": "https://esm.sh/*@preact/[email protected].2",
"@preact/signals": "https://esm.sh/*@preact/[email protected].1",
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
"twind": "https://esm.sh/[email protected]",
"twind/": "https://esm.sh/[email protected]/",
"tailwindcss": "npm:[email protected]",
"tailwindcss/": "npm:/[email protected]/",
"tailwindcss/plugin": "npm:/[email protected]/plugin.js",
"$std/": "https://deno.land/[email protected]/"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"lint": {
"rules": {
"tags": [
"fresh",
"recommended"
]
}
}
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" },
"lint": { "rules": { "tags": ["fresh", "recommended"] } },
"exclude": ["**/_fresh/*"]
}
5 changes: 2 additions & 3 deletions tests/fixture/fresh.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { defineConfig } from "$fresh/server.ts";
import twind from "$fresh/plugins/twind.ts";
import twindConfig from "./twind.config.ts";
import tailwind from "$fresh/plugins/tailwind.ts";

import { blogPlugin } from "../../src/plugin/blog.ts";
import localConfig from "./local.config.ts";

export default defineConfig({
plugins: [twind(twindConfig), blogPlugin(localConfig)],
plugins: [tailwind(), blogPlugin(localConfig)],
});
6 changes: 0 additions & 6 deletions tests/fixture/static/logo.svg

This file was deleted.

9 changes: 9 additions & 0 deletions tests/fixture/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { type Config } from "tailwindcss";
import { safelist } from "../../src/safelist.ts";

export default {
content: [
"{routes,islands,components}/**/*.{ts,tsx}",
],
safelist: safelist,
} satisfies Config;
5 changes: 0 additions & 5 deletions tests/fixture/twind.config.ts

This file was deleted.

Loading

0 comments on commit 4bbd906

Please sign in to comment.