Skip to content

Commit

Permalink
update(fix): mix frontmatters (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rooyca committed May 14, 2024
1 parent 8986798 commit 6ebea6c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docs/docs/codeblock/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
```
~~~

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
33 changes: 18 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6ebea6c

Please sign in to comment.