Skip to content

Commit

Permalink
feat: Use static site
Browse files Browse the repository at this point in the history
  • Loading branch information
phuocng committed Sep 11, 2022
1 parent dc6dd51 commit d2c3384
Show file tree
Hide file tree
Showing 117 changed files with 786 additions and 1,211 deletions.
106 changes: 106 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const fs = require('fs');
const markdownIt = require('markdown-it');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const htmlmin = require('html-minifier');

module.exports = function(eleventyConfig) {
// Copy the `img` and `css` folders to the output
eleventyConfig.addPassthroughCopy('assets');

eleventyConfig.addPlugin(syntaxHighlight);

let markdownLibrary = markdownIt({
html: true,
linkify: true
});
eleventyConfig.setLibrary('md', markdownLibrary);

// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
if (!Array.isArray(array) || array.length === 0) {
return [];
}
return (n < 0) ? array.slice(n) : array.slice(0, n);
});

eleventyConfig.addCollection('sortByTitle', function(collectionApi) {
return collectionApi.getAll()
.filter(function(item) {
let extension = item.inputPath.split('.').pop();
return extension === 'md';
})
.sort(function(a, b) {
return a.data.title - b.data.title;
});
});

eleventyConfig.addCollection('categories', function(collectionApi) {
const categories = [];
collectionApi.getAll()
.filter(function(item) {
let extension = item.inputPath.split('.').pop();
return extension === 'md';
})
.forEach((item) => {
const category = item.data.category;
if (category && !categories.includes(category)) {
categories.push(category);
}
});
return categories.sort();
});

eleventyConfig.addCollection('groupByCategories', function(collectionApi) {
const categories = {};
collectionApi.getAll()
.filter(function(item) {
let extension = item.inputPath.split('.').pop();
return extension === 'md';
})
.forEach((item) => {
const category = item.data.category;
if (!category) {
return;
}
Array.isArray(categories[category])
? categories[category].push(item)
: categories[category] = [item];
});
return categories;
});

eleventyConfig.addTransform('minify-html', function(content) {
if (this.outputPath && this.outputPath.endsWith('.html')) {
return htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
}
return content;
});

return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: [
'md',
'njk',
'html',
'liquid',
],
// Pre-process *.md files with: (default: `liquid`)
markdownTemplateEngine: 'njk',

// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: 'njk',

// These are all optional (defaults are shown):
dir: {
input: 'contents',
includes: '_includes',
data: '_data',
output: '_site'
}
};
};
2 changes: 2 additions & 0 deletions .eleventyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
README.md
posts
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.DS_Store
.netlify
.next
_site
node_modules
out
package-lock.json
5 changes: 2 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.netlify
.next
out
node_modules
_site
node_modules
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 phuoc-ng
Copyright (c) 2020 phuocng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A website introducing the APIs, well-known problems, most popular questions coul
1. Clone the project:

```shell
$ git clone https://github.com/1milligram/html-dom
$ git clone https://github.com/phuocng/html-dom
```

2. Install the dependencies:
Expand All @@ -40,16 +40,15 @@ $ npm install
3. Run it on the local:

```shell
$ npm run dev
$ npm run start
```

Look at the console to see the _Local URL_. Open it in your browser to see it in action.
Open http://localhost:8081 in your browser to see it in action.

## About

This project is developed by _Nguyen Huu Phuoc_. I love building products and sharing knowledge.

Be my friend on
* [Twitter](https://twitter.com/nghuuphuoc)
* [dev.to](https://dev.to/phuocng)
* [Github](https://github.com/phuoc-ng)
* [Github](https://github.com/phuocng)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
16 changes: 0 additions & 16 deletions components/Ad.tsx

This file was deleted.

68 changes: 0 additions & 68 deletions components/Demo.tsx

This file was deleted.

33 changes: 0 additions & 33 deletions components/FooterBlock.tsx

This file was deleted.

37 changes: 0 additions & 37 deletions components/HeaderBlock.tsx

This file was deleted.

Loading

0 comments on commit d2c3384

Please sign in to comment.