fix: some small rework for doc alignment
This commit is contained in:
@@ -125,6 +125,15 @@ function extractDataStructureNames(typeSignature: string): string[] {
|
||||
function sampleValueForField(type: string): string {
|
||||
const normalized = type.trim();
|
||||
|
||||
// Handle string literal union types like "'macro' | 'utility' | 'transform'"
|
||||
// These start with a single or double quote and contain literal enum values.
|
||||
if (/^['"]/.test(normalized)) {
|
||||
const firstLiteral = normalized.match(/['"]([^'"]+)['"]/);
|
||||
if (firstLiteral) {
|
||||
return `'${firstLiteral[1]}'`;
|
||||
}
|
||||
}
|
||||
|
||||
if (normalized.includes('string')) {
|
||||
return "'value'";
|
||||
}
|
||||
@@ -206,7 +215,7 @@ export function generateApiDocumentationMarkdownV1(): string {
|
||||
sections.push('');
|
||||
sections.push('This reference documents all Python runtime API calls available through `bds_api` in embedded Pyodide.');
|
||||
sections.push('');
|
||||
sections.push('`bds_api` is available in both **macro scripts** (executed during preview and page generation) and **transform scripts** (executed during blogmark import). In macro entrypoints, API calls run in the same runtime context as the macro and can be used to fetch posts, media, tags, or other application data.');
|
||||
sections.push('`bds_api` is available in **macro scripts** (executed during preview and page generation). Import `bds` and call API methods from an `async def` entrypoint. Transform scripts do not have access to `bds_api`.');
|
||||
sections.push('');
|
||||
sections.push('## Usage');
|
||||
sections.push('');
|
||||
|
||||
@@ -189,13 +189,19 @@ async function runMacroV1(request: PythonWorkerRequest): Promise<void> {
|
||||
|
||||
const rawJsonResult = await runtime.runPythonAsync(`
|
||||
import json as _json
|
||||
import inspect as _inspect
|
||||
_macro_ep = __bds_macro_entrypoint
|
||||
_macro_fn = globals().get(_macro_ep)
|
||||
if _macro_fn is None or not callable(_macro_fn):
|
||||
raise RuntimeError(f"Macro entrypoint '{_macro_ep}' is not callable")
|
||||
_macro_post_json = __bds_macro_post_data_json
|
||||
_macro_post = _json.loads(_macro_post_json) if _macro_post_json else None
|
||||
_json.dumps(_macro_fn(__bds_context_v1, _macro_post))
|
||||
_macro_call = _macro_fn(__bds_context_v1, _macro_post)
|
||||
if _inspect.isawaitable(_macro_call):
|
||||
_macro_result = await _macro_call
|
||||
else:
|
||||
_macro_result = _macro_call
|
||||
_json.dumps(_macro_result)
|
||||
`);
|
||||
|
||||
const parsedResult = parseMacroResultV1(JSON.parse(toResultString(rawJsonResult)));
|
||||
|
||||
Reference in New Issue
Block a user