fix(docs): correct formatting and spacing

This commit is contained in:
charlie
2026-01-14 16:03:28 +08:00
parent 9837087c74
commit 621afe27d2

View File

@@ -23,7 +23,7 @@ const results = await logseq.DB.datascriptQuery(`
`, `"my-page"`)
// Watch database changes
logseq.DB. onChanged(({ blocks, txData }) => {
logseq.DB.onChanged(({ blocks, txData }) => {
console.log('Changed blocks:', blocks)
})
@@ -113,7 +113,7 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
#### 3.1 Block Attributes
| Attribute | File Graph | DB Graph | Type | Description |
|-----------|: ----------:|:--------:|------|-------------|
|---------------------|:----------:|:--------:|--------|-------------------------------------|
| `:block/uuid` | ✅ | ✅ | UUID | Unique block identifier |
| `:block/content` | ✅ | ❌ | String | Raw block content (File Graph only) |
| `:block/title` | ❌ | ✅ | String | Block title/content (DB Graph only) |
@@ -136,7 +136,7 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
#### 3.2 Page Attributes
| Attribute | File Graph | DB Graph | Type | Description |
|-----------|:----------:|:--------:|------|-------------|
|------------------------|:----------:|:--------:|---------|------------------------------------------|
| `:block/name` | ✅ | ✅ | String | Page name (lowercase) |
| `:block/original-name` | ✅ | ✅ | String | Original page name |
| `:block/journal?` | ✅ | ✅ | Boolean | Is journal page |
@@ -148,7 +148,7 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
#### 3.3 DB Graph Specific - System Properties (Idents)
| Attribute | Type | Description |
|-----------|------|-------------|
|--------------------------------------|----------|------------------------------|
| `:logseq.property/created-at` | Int (ms) | Creation timestamp |
| `:logseq.property/updated-at` | Int (ms) | Update timestamp |
| `:logseq.property/icon` | Object | Icon definition `{type, id}` |
@@ -164,7 +164,7 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
In DB Graph, tasks use a different system based on tags/classes:
| Attribute | Description |
|-----------|-------------|
|--------------------------|-------------------------------------------------------------|
| `:block/tags` | Reference to task status class (e.g., `#logseq.class/Todo`) |
| `:logseq.task/status` | Task status property |
| `:logseq.task/priority` | Task priority property |
@@ -178,6 +178,7 @@ In DB Graph, tasks use a different system based on tags/classes:
#### 4.1 Task Queries
**File Graph:**
```typescript
// All TODOs
const todos = await logseq.DB.datascriptQuery(`
@@ -186,7 +187,7 @@ const todos = await logseq.DB.datascriptQuery(`
`)
// TODO or DOING
const activeTasks = await logseq.DB. datascriptQuery(`
const activeTasks = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:in $ [?m ...]
:where [?b :block/marker ? m]]
@@ -201,8 +202,8 @@ const priorityTasks = await logseq.DB.datascriptQuery(`
`)
// Scheduled for today
const today = new Date().toISOString().slice(0,10).replace(/-/g, '')
const scheduled = await logseq.DB. datascriptQuery(`
const today = new Date().toISOString().slice(0, 10).replace(/-/g, '')
const scheduled = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:in $ ? today
:where [?b : block/scheduled ?today]]
@@ -210,6 +211,7 @@ const scheduled = await logseq.DB. datascriptQuery(`
```
**DB Graph:**
```typescript
// All tasks with TODO status
const todos = await logseq.DB.datascriptQuery(`
@@ -220,7 +222,7 @@ const todos = await logseq.DB.datascriptQuery(`
`)
// Tasks by status property
const tasks = await logseq.DB. datascriptQuery(`
const tasks = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:where
[?b :logseq.task/status ?s]
@@ -231,6 +233,7 @@ const tasks = await logseq.DB. datascriptQuery(`
#### 4.2 Page Queries
**Both File Graph and DB Graph:**
```typescript
// All journal pages
const journals = await logseq.DB.datascriptQuery(`
@@ -239,7 +242,7 @@ const journals = await logseq.DB.datascriptQuery(`
`)
// Journals in specific month
const monthJournals = await logseq. DB.datascriptQuery(`
const monthJournals = await logseq.DB.datascriptQuery(`
[:find (pull ?p [*])
:where
[?p :block/journal? true]
@@ -249,7 +252,7 @@ const monthJournals = await logseq. DB.datascriptQuery(`
`)
// Blocks in a specific page
const blocks = await logseq.DB. datascriptQuery(`
const blocks = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:in $ ? name
:where
@@ -259,6 +262,7 @@ const blocks = await logseq.DB. datascriptQuery(`
```
**DB Graph only:**
```typescript
// Pages by type
const pages = await logseq.DB.datascriptQuery(`
@@ -267,14 +271,14 @@ const pages = await logseq.DB.datascriptQuery(`
`)
// Class/Tag pages
const classes = await logseq.DB. datascriptQuery(`
const classes = await logseq.DB.datascriptQuery(`
[:find (pull ?p [*])
:where [?p : block/type "class"]]
`)
// Recently created pages (last 7 days)
const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1000
const recentPages = await logseq. DB.datascriptQuery(`
const recentPages = await logseq.DB.datascriptQuery(`
[:find (pull ?p [*])
:where
[?p :block/type "page"]
@@ -286,9 +290,10 @@ const recentPages = await logseq. DB.datascriptQuery(`
#### 4.3 Reference Queries
**Both File Graph and DB Graph:**
```typescript
// Blocks referencing a specific page
const refs = await logseq.DB. datascriptQuery(`
const refs = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:in $ ?page
:where
@@ -297,7 +302,7 @@ const refs = await logseq.DB. datascriptQuery(`
`, `"target-page"`)
// Block references (backlinks)
const blockRefs = await logseq. DB.datascriptQuery(`
const blockRefs = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:in $ ?uuid
:where
@@ -309,9 +314,10 @@ const blockRefs = await logseq. DB.datascriptQuery(`
#### 4.4 Property Queries
**File Graph:**
```typescript
// Blocks with specific property
const withProp = await logseq. DB.datascriptQuery(`
const withProp = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:where
[?b :block/properties ?props]
@@ -329,6 +335,7 @@ const statusDone = await logseq.DB.datascriptQuery(`
```
**DB Graph:**
```typescript
// Blocks with property value (properties are direct attributes)
const withProp = await logseq.DB.datascriptQuery(`
@@ -338,7 +345,7 @@ const withProp = await logseq.DB.datascriptQuery(`
`)
// Query by property ident
const results = await logseq.DB. datascriptQuery(`
const results = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:where
[? prop :db/ident : user.property/status]
@@ -350,9 +357,10 @@ const results = await logseq.DB. datascriptQuery(`
#### 4.5 Content Search
**File Graph:**
```typescript
// Content contains keyword
const results = await logseq.DB. datascriptQuery(`
const results = await logseq.DB.datascriptQuery(`
[:find (pull ?b [*])
:where
[? b :block/content ?c]
@@ -361,6 +369,7 @@ const results = await logseq.DB. datascriptQuery(`
```
**DB Graph:**
```typescript
// Title contains keyword
const results = await logseq.DB.datascriptQuery(`
@@ -435,13 +444,13 @@ const results = await logseq.DB.datascriptQuery(`
```typescript
// Count
const count = await logseq. DB.datascriptQuery(`
const count = await logseq.DB.datascriptQuery(`
[:find (count ?b)
:where [?b : block/marker "TODO"]]
`)
// Group by page
const grouped = await logseq.DB. datascriptQuery(`
const grouped = await logseq.DB.datascriptQuery(`
[:find ? name (count ?b)
:where
[?b :block/marker "TODO"]
@@ -450,7 +459,7 @@ const grouped = await logseq.DB. datascriptQuery(`
`)
// Min/Max
const range = await logseq.DB. datascriptQuery(`
const range = await logseq.DB.datascriptQuery(`
[:find (min ?d) (max ?d)
:where
[?p :block/journal? true]
@@ -466,7 +475,7 @@ const range = await logseq.DB. datascriptQuery(`
import '@logseq/libs'
async function detectGraphType(): Promise<'db' | 'file'> {
const result = await logseq.DB. datascriptQuery(`
const result = await logseq.DB.datascriptQuery(`
[:find ? type .
:where [_ :block/type ?type]]
`)
@@ -507,7 +516,7 @@ async function main() {
logseq.Editor.registerSlashCommand('Query TODOs', async () => {
try {
const results = await queryTodos(graphType)
const todos = results?. flat() || []
const todos = results?.flat() || []
if (todos.length) {
const content = todos.map(t => `- ((${t.uuid}))`).join('\n')