Skip to content

Commit

Permalink
fix: 修复链接和搜索数量问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ziofat committed Aug 27, 2024
1 parent 26bda42 commit 85c2c63
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 32 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ jobs:
run: node common/scripts/install-run-rush.js install
- name: Rush rebuild
run: node common/scripts/install-run-rush.js rebuild --verbose
# - name: Upload index to Algolia
# run: npm run index
# env:
# ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
# continue-on-error: true
- name: Upload index to Algolia
run: cd packages/recipes && node common/scripts/install-run-rushx.js index
env:
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
continue-on-error: true
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}
Expand Down
33 changes: 33 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/recipes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"directory": "packages/recipes"
},
"scripts": {
"build": "tsx scripts/build.ts"
"build": "tsx scripts/build.ts",
"index": "tsx scripts/algolia.ts"
},
"dependencies": {
"@vuepress/plugin-git": "2.0.0-rc.42",
"algoliasearch": "^4.23.3",
"execa": "^9.1.0",
"fast-glob": "^3.2.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/recipes/scripts/algolia.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import algoliasearch from 'algoliasearch';
import { sync } from 'fast-glob';
import { getCreatedTime } from '@vuepress/plugin-git';
import { readFileSync, existsSync, writeFileSync } from 'fs';
import { readFileSync, existsSync } from 'fs';
import { resolve } from 'path';
import { cookToJson, RecipeRecord } from './cook-to-json';
import { Recipe } from './recipe';
Expand Down
20 changes: 3 additions & 17 deletions packages/theme/src/components/recipe-finder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
</div>
<div class="category-name">
<span>{{category.name}}</span>
<!-- <span>{{category.count}}</span> -->
</div>
</div>
<!-- <div class="meta">
<span class="count">共 {{count + variants}} 份食谱(含 {{variants}} 变体)</span>
</div> -->
</div>
<div class="recipes">
<RouterLink
<a
class="recipe-item"
v-for="recipe of recipes"
:key="recipe.objectID"
:to="recipe.url"
:href="recipe.url"
>
<RecipeCard :recipe="recipe" />
</RouterLink>
</a>
</div>
</template>
<script lang="ts">
Expand All @@ -42,14 +38,6 @@ export default defineComponent({
RecipeCard,
},
props: {
// count: {
// type: Number,
// default: 0,
// },
// variants: {
// type: Number,
// default: 0,
// },
recipes: {
type: Array,
default: [],
Expand Down Expand Up @@ -79,8 +67,6 @@ export default defineComponent({
active,
categories,
recipes,
// count: props.count,
// variants: props.variants,
onClick(category) {
const idx = active.indexOf(category.id);
if (idx < 0) {
Expand Down
11 changes: 4 additions & 7 deletions packages/theme/src/components/search-box.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { defineComponent, ref } from 'vue';
import algolia from 'algoliasearch';
const debounce = (fn, ms = 0) => {
Expand All @@ -25,22 +25,18 @@ const debounce = (fn, ms = 0) => {
export default defineComponent({
name: 'SearchBox',
props: {
total: {
type: Number,
default: 0,
},
},
emits: ['search'],
setup(props, context) {
const index = algolia('52DE6Z0WUS', 'e09af6bf1350a6803fbc8d6823852912').initIndex('ambrosia_recipes');
const total = ref(0);
const search = (event?: Event) => {
const query = event?.target?.value ?? '';
index.search(query, {
facets: ['courseType'],
}).then((results) => {
context.emit('search', null, results);
total.value = results.nbHits;
}).catch((err) => {
context.emit('search', err, {});
});
Expand All @@ -49,6 +45,7 @@ export default defineComponent({
search();
return {
search: debounce(search, 300),
total,
};
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/views/finder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>

<div class="results">
<RecipeFinder :count="count" :variants="variants" :recipes="recipes" :facet="facets" />
<RecipeFinder :recipes="recipes" :facet="facets" />
</div>
</div>
</template>
Expand Down
1 change: 1 addition & 0 deletions tools/eslint-config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
'@typescript-eslint/no-useless-constructor': 'error',
'import/no-unresolved': 'off',
'import/extensions': 'off',
'import/no-extraneous-dependencies': 'off',
'class-methods-use-this': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
indent: 'off',
Expand Down

0 comments on commit 85c2c63

Please # to comment.