keine Ahnung, updates der letzten paar Monate

This commit is contained in:
TheOnlySilas 2024-06-23 09:18:04 +02:00
parent e60294b950
commit 11f8caacad
9 changed files with 2787 additions and 9 deletions

2
.npmrc
View File

@ -1 +1 @@
tag-version-prefix=""
tag-version-prefix=

27
law-view.ts Normal file
View File

@ -0,0 +1,27 @@
import { ItemView, WorkspaceLeaf } from "obsidian";
export const VIEW_TYPE_EXAMPLE = "example-view";
export class ExampleView extends ItemView {
constructor(leaf: WorkspaceLeaf) {
super(leaf);
}
getViewType() {
return VIEW_TYPE_EXAMPLE;
}
getDisplayText() {
return "Example view";
}
async onOpen() {
const container = this.containerEl.children[1];
container.empty();
container.createEl("h4", { text: "Example view" });
}
async onClose() {
// Nothing to clean up.
}
}

48
main.ts
View File

@ -1,4 +1,6 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, Vault, Workspace, WorkspaceLeaf, parseFrontMatterEntry } from 'obsidian';
import { VIEW_TYPE_EXAMPLE, ExampleView } from 'law-view';
import { getData } from 'openlegaldataparser';
// Remember to rename these classes and interfaces!
@ -16,10 +18,17 @@ export default class MyPlugin extends Plugin {
async onload() {
await this.loadSettings();
//register law review view
this.registerView(
VIEW_TYPE_EXAMPLE,
(leaf) => new ExampleView(leaf)
);
// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => {
// Called when the user clicks the icon.
new Notice('This is a notice!');
new Notice('This is a not notice!');
this.activateView();
});
// Perform additional things with the ribbon
ribbonIconEl.addClass('my-plugin-ribbon-class');
@ -81,6 +90,41 @@ export default class MyPlugin extends Plugin {
onunload() {
}
async activateView() {
const { workspace } = this.app;
new Notice('Opening view');
let leaf: WorkspaceLeaf | null = null;
const leaves = workspace.getLeavesOfType(VIEW_TYPE_EXAMPLE);
const paragraphs = this.getFrontMatterMeta();
if (leaves.length > 0) {
// A leaf with our view already exists, use that
leaf = leaves[0];
} else {
// Our view could not be found in the workspace, create a new leaf
// in the right sidebar for it
leaf = workspace.getRightLeaf(false);
await leaf.setViewState({ type: VIEW_TYPE_EXAMPLE, active: true });
}
// "Reveal" the leaf in case it is in a collapsed sidebar
workspace.revealLeaf(leaf);
}
async getFrontMatterMeta(){
const { workspace } = this.app;
const actFile = workspace.getActiveFile();
if (!actFile) return
const metadata = app.metadataCache.getFileCache(actFile);
if (!metadata) return console.log("no metadata");
let returner = metadata.frontmatter;
if (returner) {
console.log(returner['§']);
console.log(await getData(returner['§'][0]));
}
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());

View File

@ -1,10 +1,10 @@
{
"id": "sample-plugin",
"name": "Sample Plugin",
"id": "obsidian-law-ref",
"name": "Law References",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"description": "Demonstrates some of the capabilities of the Obsidian API.",
"author": "Obsidian",
"description": "bliblablub",
"author": "Silas",
"authorUrl": "https://obsidian.md",
"fundingUrl": "https://obsidian.md/pricing",
"isDesktopOnly": false

27
openlegaldataparser.ts Normal file
View File

@ -0,0 +1,27 @@
import axios from 'axios';
// Configure API key authorization: api_key
const apiKey = "6e6a95bf6f99b1430ce89239aad0fd41e6159583"
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//api_key.apiKeyPrefix['Authorization'] = "Token"
var callback = function(error: string, data: string, response: string) {
if (error) {
console.log(apiKey);
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
export function getData(search: string) {
const url = 'https://de.openlegaldata.io/api/laws/search/?format=json'
return axios.get(`https://cors-anywhere.herokuapp.com/${url}&text=${encodeURIComponent(search)}`, {
headers: {
Authorization: apiKey
}
})
}

25
openlegaldataparserJS.js Normal file
View File

@ -0,0 +1,25 @@
var OldpApi = require('oldp-api');
export const testlaw = OldpApi.LawSearch("1");
var defaultClient = OldpApi.ApiClient.instance;
// Configure API key authorization: api_key
var api_key = defaultClient.authentications['api_key'];
api_key.apiKey = "6e6a95bf6f99b1430ce89239aad0fd41e6159583"
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//api_key.apiKeyPrefix['Authorization'] = "Token"
var api = new OldpApi.AnnotationLabelsApi()
var data = new OldpApi.AnnotationLabel(); // {AnnotationLabel}
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
api.annotationLabelsCreate(data, callback);

2652
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -20,5 +20,9 @@
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4"
},
"dependencies": {
"axios": "^1.7.2",
"oldp-api": "^0.1.0"
}
}

View File

@ -19,6 +19,5 @@
]
},
"include": [
"**/*.ts"
]
"**/*.ts" ]
}