mirror of
https://github.com/rooyca/obsidian-api-request.git
synced 2026-07-22 07:50:27 +00:00
update(fix): mix frontmatters (#18)
This commit is contained in:
parent
8986798a12
commit
6ebea6ca83
4 changed files with 22 additions and 19 deletions
|
|
@ -132,7 +132,7 @@ format: <h1>{}</h1> <p>{}</p>
|
|||
!!! info "In this example, first `{}` will be replaced by the title, and second `{}` will be replaced by the body."
|
||||
|
||||
|
||||
## response-type
|
||||
## res-type
|
||||
|
||||
Specifies the type of response we are getting. The default value is `json`. The available values are:
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ When the response type is `md`, the response will be rendered as markdown.
|
|||
~~~markdown
|
||||
```req
|
||||
url: https://raw.githubusercontent.com/Rooyca/Rooyca/main/README.md
|
||||
response-type: md
|
||||
res-type: md
|
||||
```
|
||||
~~~
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "api-request",
|
||||
"name": "APIRequest",
|
||||
"version": "1.2.3",
|
||||
"version": "1.2.4",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Request and retrieve data from APIs. The responses are delivered in a JSON format for easy integration with your notes.",
|
||||
"author": "rooyca",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "api-request",
|
||||
"version": "1.2.3",
|
||||
"version": "1.2.4",
|
||||
"description": "Request and retrieve data from APIs. The responses are delivered in a JSON format for easy integration with your notes.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
33
src/main.ts
33
src/main.ts
|
|
@ -1,7 +1,6 @@
|
|||
import { App, Editor, MarkdownView, Modal, Plugin, PluginSettingTab, Setting, Notice } from 'obsidian';
|
||||
import { readFrontmatter, parseFrontmatter } from './frontmatterUtils';
|
||||
import { MarkdownParser } from './mdparse.js';
|
||||
import './styles.css';
|
||||
|
||||
const parser = new MarkdownParser();
|
||||
|
||||
|
|
@ -10,20 +9,24 @@ export function checkFrontmatter(req_prop: string){
|
|||
const match = req_prop.match(regex);
|
||||
|
||||
if (match) {
|
||||
const var_name = match[0].replace(/{{this\.|}}/g, "");
|
||||
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
const markdownContent = activeView.editor.getValue();
|
||||
|
||||
try {
|
||||
const frontmatterData = parseFrontmatter(readFrontmatter(markdownContent));
|
||||
req_prop = req_prop.replace(regex, frontmatterData[var_name] || "");
|
||||
return req_prop;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
new Notice("Error: " + e.message);
|
||||
return;
|
||||
for (let i = 0; i < match.length; i++) {
|
||||
const var_name = match[i].replace(/{{this\.|}}/g, "");
|
||||
|
||||
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
const markdownContent = activeView.editor.getValue();
|
||||
|
||||
try {
|
||||
const frontmatterData = parseFrontmatter(readFrontmatter(markdownContent));
|
||||
req_prop = req_prop.replace(match[i], frontmatterData[var_name] || "");
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
new Notice("Error: " + e.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(req_prop);
|
||||
return req_prop;
|
||||
}
|
||||
|
||||
|
|
@ -165,8 +168,8 @@ export default class MainAPIR extends Plugin {
|
|||
}
|
||||
} else if (lowercaseLine.includes("url: ")) {
|
||||
URL = checkFrontmatter(line.replace(/url: /i, ""));
|
||||
} else if (lowercaseLine.includes("response-type")) {
|
||||
responseType = line.replace(/response-type: /i, "").toLowerCase();
|
||||
} else if (lowercaseLine.includes("res-type")) {
|
||||
responseType = line.replace(/res-type: /i, "").toLowerCase();
|
||||
if (!["json", "txt", "md"].includes(responseType)) {
|
||||
el.innerHTML = `Error: Response type ${responseType} not supported`;
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue