From 2120e79726588c1f3d07917f538ba5968352797e Mon Sep 17 00:00:00 2001 From: YunYouJun Date: Wed, 13 Apr 2022 23:53:07 +0800 Subject: [PATCH] chore: import json data and display --- .gitignore | 2 +- package.json | 1 + pnpm-lock.yaml | 2 ++ scripts/convert.ts | 23 +++++++++++++---------- src/components.d.ts | 1 + src/components/ChooseFood.vue | 11 +++++++++++ {public => src}/data/recipe.csv | 0 src/main.ts | 2 ++ src/pages/index.vue | 3 +++ src/styles/css-vars.scss | 12 ++++++++++++ src/styles/index.scss | 14 ++++++++++++++ unocss.config.ts | 1 + 12 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 src/components/ChooseFood.vue rename {public => src}/data/recipe.csv (100%) diff --git a/.gitignore b/.gitignore index 465919f..cf03d49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # auto generate -public/data/recipe.json +src/data/recipe.json .DS_Store .vite-ssg-dist diff --git a/package.json b/package.json index 22ac4a7..09d9a2c 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@types/markdown-it-link-attributes": "^3.0.1", "@types/nprogress": "^0.2.0", "@vitejs/plugin-vue": "^2.3.1", + "consola": "^2.15.3", "critters": "^0.0.16", "cross-env": "^7.0.3", "eslint": "^8.13.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bee047c..50a5100 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,6 +9,7 @@ specifiers: '@vitejs/plugin-vue': ^2.3.1 '@vueuse/core': ^8.2.5 '@vueuse/head': ^0.7.6 + consola: ^2.15.3 critters: ^0.0.16 cross-env: ^7.0.3 eslint: ^8.13.0 @@ -55,6 +56,7 @@ devDependencies: '@types/markdown-it-link-attributes': 3.0.1 '@types/nprogress': 0.2.0 '@vitejs/plugin-vue': 2.3.1_vite@2.9.2+vue@3.2.32 + consola: 2.15.3 critters: 0.0.16 cross-env: 7.0.3 eslint: 8.13.0 diff --git a/scripts/convert.ts b/scripts/convert.ts index 328bbfc..bb4475c 100644 --- a/scripts/convert.ts +++ b/scripts/convert.ts @@ -1,17 +1,20 @@ // convert csv to json import fs from 'fs' import path from 'path' +import consola from 'consola' import type { Recipe } from '~/types' -const recipeCsvFile = path.resolve(__dirname, '../public/data/recipe.csv') -const recipeJsonFile = path.resolve(__dirname, '../public/data/recipe.json') +const recipeCsvFile = path.resolve(__dirname, '../src/data/recipe.csv') +const recipeJsonFile = path.resolve(__dirname, '../src/data/recipe.json') function run() { const csvData = fs.readFileSync(recipeCsvFile, 'utf-8') const lines = csvData.split(/\r?\n/) - if (lines[0] !== '名称,食材,链接,标签/描述,方法,工具') - console.log('Headers Changed!') + if (lines[0].trim() !== '名称,食材,链接,标签/描述,方法,工具') { + consola.warn(`Headers Changed: ${lines[0]}`) + return + } const recipeJson: Recipe = [] const sep = '、' @@ -20,12 +23,12 @@ function run() { if (line) { const attrs = line.split(',') recipeJson.push({ - name: attrs[0], - stuff: attrs[1].split(sep), - link: attrs[2], - tags: attrs[3].split(sep), - methods: attrs[4].split(sep), - tools: attrs[5].split(sep), + name: attrs[0].trim(), + stuff: attrs[1].trim().split(sep), + link: attrs[2].trim(), + tags: attrs[3].trim().split(sep), + methods: attrs[4].trim().split(sep), + tools: attrs[5].trim().split(sep), }) } }) diff --git a/src/components.d.ts b/src/components.d.ts index c6b2fb5..b8e6c83 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -5,6 +5,7 @@ declare module '@vue/runtime-core' { export interface GlobalComponents { BaseFooter: typeof import('./components/BaseFooter.vue')['default'] + ChooseFood: typeof import('./components/ChooseFood.vue')['default'] Counter: typeof import('./components/Counter.vue')['default'] Menu: typeof import('./components/Menu.vue')['default'] README: typeof import('./components/README.md')['default'] diff --git a/src/components/ChooseFood.vue b/src/components/ChooseFood.vue new file mode 100644 index 0000000..505d5df --- /dev/null +++ b/src/components/ChooseFood.vue @@ -0,0 +1,11 @@ + + + diff --git a/public/data/recipe.csv b/src/data/recipe.csv similarity index 100% rename from public/data/recipe.csv rename to src/data/recipe.csv diff --git a/src/main.ts b/src/main.ts index dea2e57..0584e73 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,8 @@ import App from './App.vue' import '@unocss/reset/tailwind.css' import './styles/main.css' +import './styles/css-vars.scss' +import './styles/index.scss' import 'uno.css' const routes = setupLayouts(generatedRoutes) diff --git a/src/pages/index.vue b/src/pages/index.vue index 4d6b556..060b117 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -6,5 +6,8 @@

好的,今天我们来做菜!

+

+ +

diff --git a/src/styles/css-vars.scss b/src/styles/css-vars.scss index e69de29..93145eb 100644 --- a/src/styles/css-vars.scss +++ b/src/styles/css-vars.scss @@ -0,0 +1,12 @@ +:root { + --c-primary: #5fc178; + --c-text: #333; + + --c-bg: #fff; +} + +.dark { + --c-text: #fafafa; + + --c-bg: #121212; +} diff --git a/src/styles/index.scss b/src/styles/index.scss index e69de29..4bb1a81 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -0,0 +1,14 @@ +html { + color: var(--c-text); + background-color: var(--c-bg); +} + +a { + color: var(--c-text); +} + +.tag { + margin: 4px; + padding: 2px 4px; + border: 1px solid var(--c-text); +} diff --git a/unocss.config.ts b/unocss.config.ts index 72be047..1a16fb3 100644 --- a/unocss.config.ts +++ b/unocss.config.ts @@ -11,6 +11,7 @@ import { export default defineConfig({ shortcuts: [ + ['tag', 'shadow hover:shadow-md'], ['btn', 'px-4 py-1 rounded inline-block bg-green-600 text-white cursor-pointer hover:bg-green-700 disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50'], ['icon-btn', 'text-[0.9em] inline-block cursor-pointer select-none opacity-75 transition duration-200 ease-in-out hover:opacity-100 hover:text-green-600'], ],