Giter VIP home page Giter VIP logo

obsidian_customjs_demo's Introduction

CustomJS and Dataview API demo

This is a very simple demo of CustomJS and Dataview plugin.

  • I use CustomJS to fetch data from
    • Weather API https://www.weather.gov/documentation/services-web-api
    • HackersNews API https://hacker-news.firebaseio.com/v0/topstories.json
  • Dataview to display the data inside note. (I usually place this inside banner dashboard so I see it first thing in the morning)

You might need some programming knowledge to get this working or just modify this demo project to your need. I will try my best to explain every single detail so you can create your own customJS script.

At anytime you having issue with javascript, use Ctrl + Shift + i to open the developer console and see if you can track the error. Also there is a chance you need to restart your obsidian vault for plugin things to work properly the first time, try restarting if something weird is happening

Dataview

You need to install the plugin but I leave everything as default

CustomJS setup

You can specify to the parent folder of your scripts, all my scripts are inside __data__/javascript and I only have to specify to __data__ folder Alt text

Weather

Alt text

In the notes where you want to display the content add the following:

  1. Import the class using const {WeatherGov} = customJS;. This WeatherGov is the same name as your javascript file's class name.
  2. Create a new div container in your note page to hold the data
  3. Call the class function .getWeather(element) and wait for asynchronous function to finish
    1. Passing in the div container so it can be modify by javascript functions
    2. Asynchronous function are function that process in the background, so this fetching process (if very long) will not block your UI from freezing/waiting on the request to finish

Code

Just read the code, it got comment on every line

const {WeatherGov} = customJS;
let element = this.container.createEl('div', {cls: ["tailwind"]});
await WeatherGov.getWeather(element)

Hacker News

Alt text

In the notes where you want to display the content add the following:

  1. Import the class using const {News} = customJS;. This Newr is the same name as your javascript file's class name.
  2. Create a new div container in your note page to hold the data
  3. Call the class function .getNews(element) and wait for asynchronous function to finish
    1. Passing in the div container so it can be modify by javascript functions
    2. Asynchronous function are function that process in the background, so this fetching process (if very long) will not block your UI from freezing/waiting on the request to finish

Code

Just read the code, it got comment on every line

const {News} = customJS;
let element = this.container.createEl('div', {cls: ["tailwind"]});
await News.listNews(element, 15);

obsidian_customjs_demo's People

Contributors

4542elgh avatar

Stargazers

Grit avatar Debra avatar Moy avatar Anas MS avatar Jimmy Briggs avatar  avatar Lynn Zhang avatar

Watchers

 avatar

Forkers

ggmujonno

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.