Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #230 from githubnext/jaked/match-specificity
Browse files Browse the repository at this point in the history
fix fallback block for `*.md` files
  • Loading branch information
Jake Donham authored Dec 6, 2022
2 parents cff58b8 + 1b0f09d commit 17056cc
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions hooks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { Octokit } from "@octokit/rest";
import { AppContext } from "context";
import {
BlocksQueryMeta,
checkAccess,
createBranchAndPR,
CreateBranchParams,
CreateBranchResponse,
getBlocksFromRepo,
getBlocksRepos,
getBranches,
getFileContent,
getFolderContent,
Expand All @@ -15,14 +18,12 @@ import {
RepoContext,
RepoSearchResult,
searchRepos,
checkAccess,
getBlocksFromRepo,
getBlocksRepos,
} from "ghapi";
import { Base64 } from "js-base64";
import {
BlocksKeyParams,
BlockContentKeyParams,
BlocksKeyParams,
BlocksReposParams,
BranchesKeyParams,
CheckAccessParams,
FileKeyParams,
Expand All @@ -32,18 +33,18 @@ import {
InfoKeyParams,
QueryKeyMap,
TimelineKeyParams,
BlocksReposParams,
} from "lib/query-keys";
import { useRouter } from "next/router";
import pm from "picomatch";
import { useCallback, useContext, useEffect, useRef, useState } from "react";
import type { QueryFunction, UseQueryResult } from "react-query";
import {
useMutation,
UseMutationOptions,
useQuery,
useQueryClient,
UseQueryOptions,
} from "react-query";
import type { QueryFunction, UseQueryResult } from "react-query";
import { useQueryClient } from "react-query";

export function useFileContent(
params: FileKeyParams,
Expand Down Expand Up @@ -409,8 +410,15 @@ export function useManageBlock({
const blockFromMetadata = tryToGetBlockFromKey(storedDefaultBlock);
let fallbackDefaultBlock: Block = overrideDefaultBlocks[extension]
? exampleBlocks.find((b) => b.id === overrideDefaultBlocks[extension])
: // if there's a block that doesn't match * use it; otherwise use the first block (the code block)
: // if there's a block that doesn't match * use it;
exampleBlocks.find((b) => b.matches?.every((g) => g !== "*")) ||
// if there's a block that matches the current file without * use it;
exampleBlocks.find((b) => {
if (!b.matches) return false;
const matches = b.matches.filter((g) => g !== "*");
return pm(matches, { bash: true, dot: true })(path);
}) ||
// otherwise use the first block (the code block)
exampleBlocks[0];

if (
Expand Down

0 comments on commit 17056cc

Please sign in to comment.