Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
IceFlow0798 authored Apr 2, 2024
0 parents commit b832a49
Show file tree
Hide file tree
Showing 52 changed files with 6,043 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { DateTime } = require('luxon')
const navigationPlugin = require('@11ty/eleventy-navigation')
const rssPlugin = require('@11ty/eleventy-plugin-rss')

module.exports = (config) => {
config.addPlugin(navigationPlugin);
config.addPlugin(rssPlugin);

config.addPassthroughCopy('css');
config.addPassthroughCopy('static');

config.setDataDeepMerge(true);

config.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
});

config.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL, yyyy");
});

config.addCollection("tagList", collection => {
const tagsObject = {}
collection.getAll().forEach(item => {
if (!item.data.tags) return;
item.data.tags
.filter(tag => !['post', 'all'].includes(tag))
.forEach(tag => {
if(typeof tagsObject[tag] === 'undefined') {
tagsObject[tag] = 1
} else {
tagsObject[tag] += 1
}
});
});

const tagList = []
Object.keys(tagsObject).forEach(tag => {
tagList.push({ tagName: tag, tagCount: tagsObject[tag] })
})
return tagList.sort((a, b) => b.tagCount - a.tagCount)

});

}
2 changes: 2 additions & 0 deletions .eleventyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
README.md
LICENSE
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
152 changes: 152 additions & 0 deletions .github/workflows/combine-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: 'Combine PRs'

# Controls when the action will run - in this case triggered manually
on:
workflow_dispatch:
inputs:
branchPrefix:
description: 'Branch prefix to find combinable PRs based on'
required: true
default: 'dependabot'
mustBeGreen:
description: 'Only combine PRs that are green (status is success). Set to false if repo does not run checks'
type: boolean
required: true
default: true
combineBranchName:
description: 'Name of the branch to combine PRs into'
required: true
default: 'combine-prs-branch'
ignoreLabel:
description: 'Exclude PRs with this label'
required: true
default: 'nocombine'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "combine-prs"
combine-prs:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/github-script@v6
id: create-combined-pr
name: Create Combined PR
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pulls = await github.paginate('GET /repos/:owner/:repo/pulls', {
owner: context.repo.owner,
repo: context.repo.repo
});
let branchesAndPRStrings = [];
let baseBranch = null;
let baseBranchSHA = null;
for (const pull of pulls) {
const branch = pull['head']['ref'];
console.log('Pull for branch: ' + branch);
if (branch.startsWith('${{ github.event.inputs.branchPrefix }}')) {
console.log('Branch matched prefix: ' + branch);
let statusOK = true;
if(${{ github.event.inputs.mustBeGreen }}) {
console.log('Checking green status: ' + branch);
const stateQuery = `query($owner: String!, $repo: String!, $pull_number: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number:$pull_number) {
commits(last: 1) {
nodes {
commit {
statusCheckRollup {
state
}
}
}
}
}
}
}`
const vars = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull['number']
};
const result = await github.graphql(stateQuery, vars);
const [{ commit }] = result.repository.pullRequest.commits.nodes;
const state = commit.statusCheckRollup.state
console.log('Validating status: ' + state);
if(state != 'SUCCESS') {
console.log('Discarding ' + branch + ' with status ' + state);
statusOK = false;
}
}
console.log('Checking labels: ' + branch);
const labels = pull['labels'];
for(const label of labels) {
const labelName = label['name'];
console.log('Checking label: ' + labelName);
if(labelName == '${{ github.event.inputs.ignoreLabel }}') {
console.log('Discarding ' + branch + ' with label ' + labelName);
statusOK = false;
}
}
if (statusOK) {
console.log('Adding branch to array: ' + branch);
const prString = '#' + pull['number'] + ' ' + pull['title'];
branchesAndPRStrings.push({ branch, prString });
baseBranch = pull['base']['ref'];
baseBranchSHA = pull['base']['sha'];
}
}
}
if (branchesAndPRStrings.length == 0) {
core.setFailed('No PRs/branches matched criteria');
return;
}
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/heads/' + '${{ github.event.inputs.combineBranchName }}',
sha: baseBranchSHA
});
} catch (error) {
console.log(error);
core.setFailed('Failed to create combined branch - maybe a branch by that name already exists?');
return;
}
let combinedPRs = [];
let mergeFailedPRs = [];
for(const { branch, prString } of branchesAndPRStrings) {
try {
await github.rest.repos.merge({
owner: context.repo.owner,
repo: context.repo.repo,
base: '${{ github.event.inputs.combineBranchName }}',
head: branch,
});
console.log('Merged branch ' + branch);
combinedPRs.push(prString);
} catch (error) {
console.log('Failed to merge branch ' + branch);
mergeFailedPRs.push(prString);
}
}
console.log('Creating combined PR');
const combinedPRsString = combinedPRs.join('\n');
let body = '✅ This PR was created by the Combine PRs action by combining the following PRs:\n' + combinedPRsString;
if(mergeFailedPRs.length > 0) {
const mergeFailedPRsString = mergeFailedPRs.join('\n');
body += '\n\n⚠️ The following PRs were left out due to merge conflicts:\n' + mergeFailedPRsString
}
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Combined PR',
head: '${{ github.event.inputs.combineBranchName }}',
base: baseBranch,
body: body
});
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vscode
_site
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: node_js
dist: focal
node_js:
- 18
before_script:
- npm install
script: npm run build:stylus && eleventy --pathprefix=eleventy-stylus-blog-theme
deploy:
local-dir: _site
provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN
keep-history: true
target_branch: gh-pages
on:
branch: main
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Aditya Raj

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Eleventy + Stylus Blog theme

[![Netlify Status](https://api.netlify.com/api/v1/badges/a180e099-11d2-49d4-9697-910d56980343/deploy-status)](https://app.netlify.com/sites/eleventy-stylus-blog-theme/deploys)
[![Build Status](https://travis-ci.com/ar363/eleventy-stylus-blog-theme.svg?branch=main)](https://travis-ci.com/ar363/eleventy-stylus-blog-theme)
[![Vercel Status](https://vercel-badge-ar363.vercel.app/?app=eleventy-stylus-blog-theme)](https://github.com/ar363/eleventy-stylus-blog-theme/deployments/activity_log?environment=Production)

A theme repository that contains a blog built with [Eleventy](https://github.com/11ty/eleventy) and [Stylus](https://stylus-lang.com/)

## Features
- 100% Lighthouse scores
- Toggleable dark theme (PS. theme preference is also stored in `localStorage`)
- Tags as taxonomy
- Stylus CSS preprocessor
- Integrated with Eleventy's official [navigation plugin](https://www.11ty.dev/docs/plugins/navigation/)
- Also generates Atom RSS Feed with Eleventy's official [RSS plugin](https://www.11ty.dev/docs/plugins/rss/)
- Sitemap generation
- Non-post pages support (eg. About page, Contact page)
- Modular type scale implemented in with Stylus

## Demos

- Vercel: https://eleventy-stylus-blog-theme.vercel.app/
- Netlify: https://eleventy-stylus-blog-theme.netlify.app/
- Github Pages: https://ar363.github.io/eleventy-stylus-blog-theme/

## Screenshots

Light theme
![light theme website homepage screenshot](screenshot.png?raw=true)

Dark theme
![dark theme website homepage screenshot](screenshot-dark.png?raw=true)

## Deploy this template to your own site

Get your site up and running with a few clicks

- [Deploy on Netlify](https://app.netlify.com/start/deploy?repository=https://github.com/ar363/eleventy-stylus-blog-theme)
- [Deploy on Vercel](https://vercel.com/import/project?template=ar363%2Feleventy-stylus-blog-theme)

## Prerequisites for local development
[Node.js LTS](https://nodejs.org/en/)

## Getting started locally

1. Clone this repo
```
git clone https://github.com/ar363/eleventy-stylus-blog-theme my-blog
```

2. Navigate to the blog directory
```
cd my-blog
```

3. Install dependencies
```
npm i
```
4. Edit `_data/site.js` according to your site preferences

5. Also optionally modify `stylus/abstracts/variables.styl` according to your preference

To watch for changes in Eleventy and Stylus, use `npm run dev`

To build without watching for changes, use `npm run build`
6 changes: 6 additions & 0 deletions _data/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
currentYear() {
const today = new Date();
return today.getFullYear();
}
};
20 changes: 20 additions & 0 deletions _data/site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
meta: {
title: "My Purple Blog",
description: "Lorem ipsum dolor sit amet consectetur adipisicing elit.",
lang: "en",
siteUrl: "https://example.com/",
},
feed: { // used in feed.xml.njk
subtitle: "Lorem ipsum dolor sit amet consecuteor",
filename: "atom.xml",
path: "/atom.xml",
id: "https://example.com/",
authorName: "John Doe",
authorEmail: "[email protected]"
},
hero: { // used in hero section of main page ie. index.html.njk
title: "Welcome to my purple blog",
description: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolores accusantium deserunt odio esse."
}
}
3 changes: 3 additions & 0 deletions _includes/components/footer.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<footer class="footer">
&copy; {{ helpers.currentYear() }} - {{ site.meta.title }}
</footer>
40 changes: 40 additions & 0 deletions _includes/components/navbar.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% set navPages = collections.all | eleventyNavigation %}
<nav class="navbar">
<div class="navbar__inner">
<a class="navbar__logo" href="{{ '/' | url }}">{{ site.meta.title }}</a>

<div class="navbar__mobile-options">
<div class="navbar__button dark-toggle" aria-label="toggle dark theme">
<img src="{{ '/static/img/moon.svg' | url }}" alt="">
</div>
<button class="navbar__button navbar__hamburger" aria-expanded="false" aria-label="toggle menu">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#333333">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/>
</svg>
</button>
</div>

<div class="navbar__links">
{% for entry in navPages %}
<a class="navbar__link {% if entry.url == page.url %}navbar__link--active{% endif %}" href="{{ entry.url | url }}">
{{ entry.title }}
</a>
{%- endfor %}

<div class="navbar__button dark-toggle" aria-label="toggle dark theme">
<img src="{{ '/static/img/moon.svg' | url }}" alt="">
</div>

</div>
</div>

<div class="navbar__mobile-links">
{% for entry in navPages %}
<a class="navbar__mobile-link {% if entry.url == page.url %}navbar__mobile-link--active{% endif %}" href="{{ entry.url | url }}">
{{ entry.title }}
</a>
{%- endfor %}
</div>

</nav>
Loading

0 comments on commit b832a49

Please sign in to comment.