Skip to content

Instantly share code, notes, and snippets.

@1chooo
Last active January 6, 2024 16:09
Show Gist options
  • Save 1chooo/322ba1fb8f2f81b6060570b8d78fe074 to your computer and use it in GitHub Desktop.
Save 1chooo/322ba1fb8f2f81b6060570b8d78fe074 to your computer and use it in GitHub Desktop.
Hello Gist Backend blog #page #test

Intro

This is a test blog post for github page

Playground

Katex testing

$$ S = \sum_{i = 0}^{n} f\left(i\right) $$

This is a oneline $e^{i\pi}+1=0$ test

Double $e^{i\pi}+1=0$ $e^{i\pi}+1=0$ test

Code syntex testing

export class Loader{

    // URL: String;
    // OPTIONS: Object
    // POSTLOAD_FUNCTION: (data: String) => void;

    constructor(url, func, options = {}, autorun = true){
        this.POSTLOAD_FUNCTION = func;
        this.OPTIONS = options;
        this.URL = url;

        if (autorun){
            this.run();
        }
    }

    async run(){

        const response = await fetch(this.URL, this.OPTIONS).catch(e => {console.log(`${e}`)});

        this.POSTLOAD_FUNCTION(response);

        return;
        
    }

}

class Gist_Loader extends Loader{

    constructor(){
        super(undefined,undefined,undefined,false);
        this.CONFIG = undefined;
    }

    loadConfig(config){

        if(config.env === 'dev'){
            this.OPTIONS.headers = {
                Authorization: `token ${config.GITHUB_TOKEN}`
            }
        }

        this.CONFIG = config;
    
    }

    readRoute(){

        this.URL = `https://api.github.com/users/${this.CONFIG.GITHUB_USERNAME}/gists`;
        this.POSTLOAD_FUNCTION = async data => {

            const blog_post_field = document.getElementById('blog-post-field');

            const gists = await data.json();

            for (const post of gists){
                if (post.description.includes('#page')){

                    const post_tags = post.description.split('#').slice(2,);
                    const post_create = new Date(post.created_at).toDateString().slice(4,);
                    const abstract = post.description.split('#')[0];
                    let title = '';

                    for (const [key, value] of Object.entries(post.files)){
                        title = key;
                    }

                    const post_element = document.createElement('li');
                    post_element.classList.add('blog-post-item');
                    post_element.innerHTML = `
                        <a href="#">
                            
                            <div class="blog-content">

                                <div class="blog-meta">
                                    <p class="blog-category">${post_tags[0]}</p>

                                    <span class="dot"></span>

                                    <time datetime="${post.created_at.split('T')[0]}">${post_create}</time>
                                </div>

                                <h3 class="h3 blog-item-title">${title.replace('.md', '')}</h3>

                                <p class="blog-text">
                                    ${abstract}
                                </p>

                            </div>

                        </a>
                    `
                    blog_post_field.appendChild(post_element);
                }
            }
        };

        this.run();

    }

    fetch(url, func){

        if (this.CONFIG == undefined){

            console.log("still waiting for loading config");

            setTimeout(
                this.fetch(url, func), 500
            );

            return;
        }

        this.URL = `https://api.github.com/gists/${url}`;
        this.POSTLOAD_FUNCTION = func;

        this.run()
    }
}

export const GIST_LOADER = new Gist_Loader();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment