GitHub

您所在的位置:网站首页 现代化收割机功能介绍 GitHub

GitHub

2024-07-16 00:41:57| 来源: 网络整理| 查看: 265

Screen.Recording.2022.11.06.at.9.59.17.AM.mp4

crates.io

logo

CodeStage is a static site generator to create javascript playgrounds. I implemented this to generate code samples for my WebGPU tutorial project. CodeStage was inspired by the following sites:

Monaco | WebGPU samples | Bauble | Goplay

All these sites seem to build their own solution. CodeStage, on the other hand, is a free and reusable solution.

Key features Mutable code samples, easy to conduct experiments on Samples can be navigated by a menu supporting nested items No backend is needed

To see a demo of a deployed CodeStage site: Demo. Some samples used in this demo come from webglsamples.

Installation cargo install codestage --version 0.1.0-alpha.9 Usage

Create a project folder and a project file codestage.toml

# Title of the project (must have). title = "CodeStage example" # Link to the repository (optional). repo = "xxx" # If not deployed under the root directory, this will be needed. The first slash is required (optional). prefix = "/codestage" # Specify the output folder (optional). target = "dist" # Link to the deployed site, this will be used for meta tags (optional). url = "https://shi-yan.github.io/codestage/" # Image used for meta tags (optional). meta_image = "meta.png" # Description used for meta tags (optional). description = """ CodeStage is a static site generator to build JS playground demos.""" # Utility folders are shared by all samples in the project (optional). utilities = [ "utility_folder_1", "utility_folder_2" ] # The following is the table of content, which will be rendered in the menu area. # The content field is an array of chapters. # Each chapter must have a title # A chapter can have a folder. When a folder is provided and when the menu item is clicked, we will load the sample in the folder. If no folder is provided, this menu item will not be clickable. [[content]] title = "chapter 1" folder = "test_base" # A list of files we want to load into the editor. All files in the above folder will be deployed, but only these files in that folder will be loaded into the editor. [[content.files]] # Each folder must have an index.html, this file is the entrypoint. filename = "index.html" # is_readonly will make a file immutable (optional). is_readonly = true # Chapters can be nested by using the sub_chapters field. This field is an array, its format is the same as the content field. [[content.sub_chapters]] title = "chapter 1.1" folder = "test_base" [[content.sub_chapters.files]] filename = "index.html" # Another level of nested chapter [[content.sub_chapters.sub_chapters]] title = "chapter 1.1.1" folder = "test_base" [[content.sub_chapters.sub_chapters.files]] filename = "index.html" [[content]] title = "chapter 2" folder = "test_base" [[content.files]] filename = "index.html" is_readonly = true

Each indivisual sample should be in a separate folder. Under each folder, there must be an index.html file. This will be the entrypoint for the sample. When a user clicks the run button, we will load and display this index.html file.

There can be a utility folder housing the common files that are shared by all samples.

A typical project's folder structure should look like this:

my-codestage-project/ ├─ sample_1/ │ ├─ favicon.ico │ ├─ index.html │ ├─ style.css ├─ sample_2/ │ ├─ index.html ├─ sample_3/ │ ├─ index.html │ ├─ index.css │ ├─ index.js ├─ utility_folder/ │ ├─ utility_script.js ├─ utility_folder_2/ │ ├─ test.png ├─ codestage.toml ├─ meta_image.png ├─ README.md

It is not necessary to develop the samples using the CodeStage editor. They can be developed using a more familiar and advanced editor.

Once development is done, run this command to build your project:

codestage --target

The static site is generated under

If the site will be deployed to a subpath of a domain, indead of the root, for example: https://example.com/my_samples, We need to specify the path prefix (/my_sample). This can be done with either the commandline argument --prefix or the codestage.toml file.

The commandline options have higher priority than the toml file. If you want to do any adhoc config changes, you can use the commandline.

Example

The example_project folder contains an example project. To build it:

cd example_project codestage

The generated site will be under example_project/dist

Build cd frontend npm i --save npm run build cd cli cargo build --release Implementation details

When we build a CodeStage project, we first validate the codestage.toml file, copy all sample and utility folders to the target folder. We then generate a json file called manifest.json, which contains the menu structure for the project. We also output the frontend code into the target folder. When the project is loaded into browser, we fetch the manifest file first to populate the menu structure. When a menu item is clicked, we load the corresponding files as defined in the codestage.toml file into the editor. A user can freely change the sample code using the in-browser editor. When the run button is clicked, we use the following mechanism to assemble the program:

We first create a dom tree using the content of the index.html file. We scan for all link tags. For all link tags that have the href attribute matching a modified css file, we will replace their textContent with the modified code. We scan for all script tags. For all script tags that have the src attribute matching a modified js file, we will replace their textContent with the modified code. Finally we inject a base tag into the document, so that we can use the sample's folder as the root. The dom tree assembled above will be stuffed into an iframe for execution.

The in-browser editor is built using Monaco.



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭