Skip to content

Commit

Permalink
feat(context): level value & access to current page
Browse files Browse the repository at this point in the history
  • Loading branch information
stdword committed Mar 19, 2023
1 parent 014ccbf commit 161f63e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/utils/logseq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import { isInteger, isUUID } from './parsing'
export type IBlockNode = Required<Pick<IBatchBlock, 'content' | 'children'>>
export function walkBlockTree(
root: IBatchBlock,
callback: ((b: IBatchBlock) => string | void),
callback: ((b: IBatchBlock, lvl: number) => string | void),
level: number = 0,
): IBlockNode {
return {
content: callback(root) ?? '',
children: (root.children || []).map(b => walkBlockTree(b as IBlockNode, callback)),
content: callback(root, level) ?? '',
children: (root.children || []).map(
b => walkBlockTree(b as IBlockNode, callback, level + 1)
),
}
}

Expand Down Expand Up @@ -127,11 +130,9 @@ export async function getPage(ref: LogseqReference): Promise<PageEntity | null>
}

export async function getBlock(
ref: LogseqReference,
{
byProperty = '',
includeChildren = false,
}: { byProperty?: string, includeChildren?: boolean }
ref: LogseqReference, {
byProperty = '',
includeChildren = false }: { byProperty?: string, includeChildren?: boolean }
): Promise<[BlockEntity | null, LogseqReferenceAccessType]> {
if (['page', 'tag'].includes(ref.type))
return [ null, 'page']
Expand Down
5 changes: 4 additions & 1 deletion src/utils/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ const quotesValues = [
'\u301E'.repeat(2), // DOUBLE PRIME QUOTATION MARK
]


export function isUUID(str: string) {
const regex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
return !!str.match(regex)
}

export function isObject(item: any): boolean {
return (item && typeof item === 'object' && !Array.isArray(item))
}

export function isBoolean(obj: any): boolean {
// source: https://stackoverflow.com/a/28814865
if (typeof obj === typeof true)
Expand Down

0 comments on commit 161f63e

Please sign in to comment.