{"id":23366986,"url":"https://github.com/mattstypa/blego","last_synced_at":"2025-04-10T14:20:54.253Z","repository":{"id":31196017,"uuid":"124989555","full_name":"MattStypa/blego","owner":"MattStypa","description":"Static site generator powered by collections and relationships.","archived":false,"fork":false,"pushed_at":"2023-07-18T20:14:59.000Z","size":554,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-10T08:46:48.224Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://blego.js.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MattStypa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-13T03:54:50.000Z","updated_at":"2023-03-16T03:30:17.000Z","dependencies_parsed_at":"2024-12-21T14:35:17.580Z","dependency_job_id":"085ae837-a994-4af0-84e8-38b8f6a974cd","html_url":"https://github.com/MattStypa/blego","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattStypa%2Fblego","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattStypa%2Fblego/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattStypa%2Fblego/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattStypa%2Fblego/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MattStypa","download_url":"https://codeload.github.com/MattStypa/blego/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248233936,"owners_count":21069493,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-21T14:35:02.542Z","updated_at":"2025-04-10T14:20:54.237Z","avatar_url":"https://github.com/MattStypa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/MattStypa/assets/master/blego/blego.png\"\u003e\u003c/p\u003e\n\n\n# Blego\nBlego is an exceptionally powerful and easy to use static site generator. It's a great choice for beginners AND veterans.\n\n## Progressively dynamic templates\nBlego makes developing purpose-built templates effortless but it also enables a progressive transformation of static HTML sites. This makes Blego the perfect companion for thousands of existing HTML templates.\n\n## Relational data model\nBlego is powered by an unopinionated data model that supports multiple types of relationships. It is trivial to access related data across multiple levels of hierarchy.\n\n## Flexibility\nBlego is flexible enough to generate any type of a website like Blogs, Stores or Wikis. In fact, it can handle a lot more than just websites. It can generate XMLs, PDFs or even images.\n\n\n\n# Using Blego\n## Requirements\nBlego requires [Node.js 18](https://nodejs.org) or newer. Visit [https://nodejs.org](https://nodejs.org/) to learn more.\n\n## Creating a project\n```sh\nnpx blego new my-project\n```\n\nThis will create a new directory with a simple Blego project already set up. You can replace `my-project` with any directory name you like.\n\n## Building a project\n```sh\nnpx blego build\n```\n\nThis will build your project and save it to the `dist` directory.\n\n## Serving a project\n```sh\nnpx blego serve\n```\n\nThis will start a web server from the `dist` directory. Visit [http://localhost:3000](http://localhost:3000) to see your generated project.\n\n## File system\nStandard Blego project is preconfigured with the following files and directories.\n\n`data`: Contains data files parsed into Stores. [Learn more](#Data).\n\n`globals`: Contains data files available globally. [Learn more](#Globals).\n\n`static`: Contains files copied directly to the `dist` directory. [Learn more](#static-files).\n\n`template`: Contains [Handlebars.js](https://handlebarsjs.com/) template files. [Learn more](#Template)\n\n`blego.js`: This is the brain of your Blego project. This file contains definitions of all relationships and instructions on how to build your project.\n\n## Building pages\nTo build a page add the following code to the `blego.js` file.\n\n```js\nblego.page('page.html', 'welcome.html', { title: 'Hello World' });\n```\n\nThis will create `page.html` using the `welcome.html` template populated with data passed in the last argument.\n\n## Template\nTemplate files use [Handlebars.js](https://handlebarsjs.com/) to fill in static markup with dynamic content.\n\n```html\n\u003cdiv class=\"entry\"\u003e\n  \u003ch1\u003e{{ title }}\u003c/h1\u003e\n  \u003cdiv class=\"body\"\u003e\n    {{ body }}\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n\nAll templates are treated as [Handlebars.js partials](https://handlebarsjs.com/partials.html). This means that you can compose templates using shared components.\n\n```html\n{{\u003e header.html }}\nHello World\n{{\u003e footer.html }}\n```\n\nThere is a lot more that [Handlebars.js](https://handlebarsjs.com/) can do. Visit [https://handlebarsjs.com](https://handlebarsjs.com/) to learn more.\n\n## Macros\nMacros allow you to call Javascript functions from your template.\n\nFor example, you may want to report when the page was generated.\n\nFirst you need to register a macro in the `blego.js` file.\n\n```js\nblego.macro('currentDateTime', () =\u003e new Date().toLocaleString());\n```\n\nYou can then use it in your templates.\n\n```html\n\u003cspan\u003e{{ currentDateTime }}\u003c/span\u003e\n```\n\nMacros can also accept arguments.\n\n```js\nblego.macro('getUserAge', (user) =\u003e user.age || 'Age not available');\n```\n\n```html\n\u003cspan\u003e{{ getUserAge user }}\u003c/span\u003e\n```\n\nMacros use [Handlebars.js helpers](https://handlebarsjs.com/#helpers). Visit [https://handlebarsjs.com/#helpers](https://handlebarsjs.com/#helpers) to learn more.\n\n## Static files\nNot all files used by a website are dynamically generated. Put your static files like images, CSS, etc. in the `static` directory and Blego will automatically copy them to the `dist` directory when building.\n\n## Data\nBlego creates data Stores by parsing files from the `data` directory.\n\nFirst tier subdirectories represent the Store name while the remaining file path represents the Record key. File extension is omitted from the Record key.\n\n```\n.\n+- Data\n   +- Pages\n      +- home.md\n      +- about.md\n      +- about\n         +- contact.md\n```\n\nGiven this file structure, Blego will create a Store called `Pages` with 3 Records. The Records will have the following keys.\n\n```\n- home\n- about\n- about/contact\n```\n\n## Stores\nStores provide many ways of accessing and manipulating the Records.\n\nFor example, you may want to get twitter handles for the five newest users.\n\n```js\nblego.data.Users.sortBy('joinedAt').reverse().take(5).pluck('twitter');\n```\n\nSee the [API reference](API.md#store) to learn more.\n\n## Data file types\nBlego can parse many different data file types.\n\n- **Markdown** files use `.md` file extension.\n- **HTML** files use `.html` file extension.\n- **Javascript** files use `.js` file extension.\n- **JSON** files use `.json` file extension.\n- **YAML** files use `.yaml` file extension.\n\nMarkdown and HTML data files support [Front Matter](https://github.com/jxson/front-matter). Meta data provided is exposed as parameters of the Record while the content is available via the `body` parameter.\n\nVisit [https://github.com/jxson/front-matter](https://github.com/jxson/front-matter) to learn more about [Front Matter](https://github.com/jxson/front-matter).\n\nJavascript data files must export an object which will be merged into the Record.\n\nJSON and YAML files are parsed into Javascript object and merged into the Record.\n\n## Globals\n\nSome data may need to be available globally. Data files in the `globals` directory will  be automatically made available in every template file.\n\n**Note**: Global data is a Javascript object and not a Store.\n\nBelow is a simple `config.json` file placed in the `globals` directory.\n\n```json\n{\n  \"site_name\": \"My Project\"\n}\n```\n\nThe data can be accessed in any template.\n\n```html\n\u003ch1\u003e{{ config.site_name }}\u003c/h1\u003e\n```\n\n## Relationships\n\nBlego must be told how the data models relate to each other. You may be used to thinking about relationships as one-to-one or one-to-many. However, it is important to also understand the direction of the relationship.\n\nFor example; A team has many players but a player has one team.\n\nWhen creating a relationship between Books and Authors it makes a lot more sense to define the Authors in the Book model. But, this relationship must work both ways.\n\nTo define bidirectional relationship between Books and Authors you need to add the following code to the `blego.js` file.\n\n```\nblego.data.Books.linkToMany(blego.data.Authors, 'authors');\nblego.data.Authors.linkFromMany(blego.data.Books, 'authors', 'books');\n```\n\nThis will replace the Author keys in `authors` property of Book Records with actual Author Records. And, add `books` property to the Author Records containing related Book Records.\n\nSee the [API reference](API.md#blegodatastorelinktoonerelatedstore-prop) to learn more.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattstypa%2Fblego","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattstypa%2Fblego","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattstypa%2Fblego/lists"}