Browse Source

Migrating from custom Pug setup to Hugo

master
Mobius K 10 months ago
parent
commit
b18376e1c8
  1. BIN
      assets/apple-touch-icon.png
  2. 8
      assets/index.scss
  3. 25
      assets/index.ts
  4. 17
      assets/manifest.json
  5. 3
      assets/sentry.ts
  6. 8
      config/_default/config.yaml
  7. 2
      config/primary/config.yaml
  8. 2
      config/secondary/config.yaml
  9. 9
      content/404.html
  10. 10
      content/500.html
  11. 3
      content/_index.html
  12. 99
      data/codes.yaml
  13. 5
      html/routes/404.pug
  14. 7
      html/routes/500.pug
  15. 167
      html/routes/index.pug
  16. 5
      html/routes/offline.pug
  17. 35
      html/templates/layout.pug
  18. 65
      layouts/_default/baseof.html
  19. 3
      layouts/_default/single.html
  20. 92
      layouts/index.html
  21. 42
      scripts/service-worker.ts
  22. 0
      static/favicon.ico
  23. 0
      static/icon.png

BIN
assets/apple-touch-icon.png

Before

Width: 192  |  Height: 192  |  Size: 28 KiB

8
styles/index.scss → assets/index.scss

@ -18,9 +18,9 @@ $global-emphasis-color: $text-color;
$global-link-color: lighten($secondary-brand-color, 25%);
$global-link-hover-color: lighten($secondary-brand-color, 35%);
@import "uikit/src/scss/variables";
@import "uikit/src/scss/mixins";
@import "uikit/src/scss/uikit";
@import "node_modules/uikit/src/scss/variables";
@import "node_modules/uikit/src/scss/mixins";
@import "node_modules/uikit/src/scss/uikit";
// Content wrapper
@ -33,7 +33,7 @@ html {
}
body {
border-color: $secondary-brand-color;
border-color: $primary-brand-color;
border-style: solid;
border-width: 5px 0 4px;
display: flex;

25
scripts/index.ts → assets/index.ts

@ -1,26 +1,6 @@
import { release } from "shared/config/build.dev";
import { ErrorMonitor } from "shared/scripts/error-monitor";
// This entire application relies on bitwise operators, so we'll stop tslint from complaining right away
// tslint:disable:no-bitwise
if (release) {
// Start the error watcher
new ErrorMonitor(
"bluetooth-class",
"https://ab6fd35ef01e438eb32719f4d92ee084@o127434.ingest.sentry.io/5178420"
);
// Load our service worker to enable PWA functionality
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("/service-worker.js").then();
});
}
}
// Container for our bluetooth class code
let bluetoothClass = 0;
@ -56,14 +36,14 @@ function updateBluetoothMinorDeviceFields(): void {
let majorDeviceId: string;
if (majorDeviceRadio != null) {
majorDeviceId = majorDeviceRadio.id.replace("majorDevice", "");
majorDeviceId = majorDeviceRadio.id;
}
// Hide all minor device fields that don't match our major device id and uncheck them
minorDeviceGroups.forEach((element: HTMLElement) => {
element.querySelectorAll("input").forEach((minorDevice: HTMLInputElement) => minorDevice.checked = false);
element.setAttribute("hidden", "true");
if (element.className.includes(majorDeviceId)) {
if (element.className.startsWith(majorDeviceId + " ")) {
element.removeAttribute("hidden");
}
});
@ -92,5 +72,6 @@ checkboxesAndRadios.forEach((element: HTMLInputElement) => {
});
// Default the bluetooth class field and minor device fields on page load
checkboxesAndRadios.forEach((element: HTMLInputElement) => element.checked = false);
updateBluetoothClassField();
updateBluetoothMinorDeviceFields();

17
assets/manifest.json

@ -1,17 +0,0 @@
{
"background_color": "#242424",
"display": "standalone",
"icons": [
{
"sizes": "512x512",
"src": "icon.png",
"type": "image/png",
"purpose": "any maskable"
}
],
"name": "Bluetooth Class",
"scope": "/",
"short_name": "Bluetooth Class",
"start_url": "/index.html",
"theme_color": "#3B5998"
}

3
assets/sentry.ts

@ -0,0 +1,3 @@
import {ErrorMonitor} from "shared/scripts/error-monitor";
new ErrorMonitor("https://ab6fd35ef01e438eb32719f4d92ee084@o127434.ingest.sentry.io/5178420");

8
config/_default/config.yaml

@ -0,0 +1,8 @@
# Where to read files from (relative to parent mono-repo)
assetDir: bluetooth-class/assets
contentDir: bluetooth-class/content
dataDir: bluetooth-class/data
layoutDir: bluetooth-class/layouts
staticDir:
- shared/static
- bluetooth-class/static

2
config/primary/config.yaml

@ -0,0 +1,2 @@
# Hostname root
baseURL: "https://bluetooth-class.mobiusk.com/"

2
config/secondary/config.yaml

@ -0,0 +1,2 @@
# Hostname root
baseURL: "https://qa-bluetooth-class.mobiusk.com/"

9
content/404.html

@ -0,0 +1,9 @@
---
title: Content not found
url: 404.html
---
<p>
<a href="/">&lArr; Return to home page</a>
The file you are looking for doesn't exist here
</p>

10
content/500.html

@ -0,0 +1,10 @@
---
title: Error
url: 500.html
---
<p>
<a href="/">&lArr; Return to home page</a>
Something went wrong with this website.
An alert has likely been sent to me, but an email is the fastest way to get bugs fixed and is greatly appreciated.
</p>

3
content/_index.html

@ -0,0 +1,3 @@
---
title: Code builder
---

99
data/codes.yaml

@ -0,0 +1,99 @@
majorServices:
- 0x800000: "Information"
- 0x400000: "Telephony"
- 0x200000: "Audio"
- 0x100000: "Transfer"
- 0x080000: "Capturing"
- 0x040000: "Rendering"
- 0x020000: "Access point"
- 0x010000: "Positioning"
- 0x002000: "Limited discovery"
majorDevices:
- code: 0x1F00
title: "Uncategorized"
- code: 0x0800
title: "Toy"
minorDevices:
- 0x14: "Game"
- 0x10: "Controller"
- 0x0C: "Doll"
- 0x08: "Vehicle"
- 0x04: "Robot"
- code: 0x0700
title: "Wearable"
minorDevices:
- 0x14: "Glasses"
- 0x10: "Helmet"
- 0x0C: "Jacket"
- 0x08: "Pager"
- 0x04: "Watch"
- code: 0x0600
title: "Imaging"
minorDevices:
- 0x80: "Printer"
- 0x40: "Scanner"
- 0x20: "Camera"
- 0x10: "Display"
- code: 0x0500
title: "Peripheral"
minorDevices:
- 0x18: "Card reader"
- 0x14: "Digitizer"
- 0x10: "Sensor"
- 0x0C: "Remote control"
- 0x08: "Gamepad"
- 0x04: "Joystick"
- 0x80: "Pointer"
- 0x40: "Keyboard"
- 0x00: "Uncategorized"
- code: 0x0400
title: "Media"
minorDevices:
- 0x40: "Conferencing"
- 0x38: "Monitor"
- 0x30: "Video camera"
- 0x20: "Car audio"
- 0x18: "Headphones"
- 0x14: "Loudspeaker"
- 0x10: "Microphone"
- 0x04: "Headset"
- 0x00: "Uncategorized"
- code: 0x0300
title: "Access point"
minorDevices:
- 0xE0: "Unavailable"
- 0xC0: "83-99% use" # Level 6
- 0xA0: "67-83% use" # Level 5
- 0x80: "50-67% use" # Level 4
- 0x60: "33-50% use" # Level 3
- 0x40: "17-33% use" # Level 2
- 0x20: "1-17% use" # Level 1
- 0x00: "Available"
- code: 0x0200
title: "Phone"
minorDevices:
- 0x08: "Cordless"
- 0x04: "Cell"
- 0x00: "Uncategorized"
- code: 0x0100
title: "Computer"
minorDevices:
- 0x18: "Watch"
- 0x14: "PDA"
- 0x0C: "Laptop"
- 0x08: "Server"
- 0x04: "Desktop"
- 0x00: "Uncategorized"
- code: 0x0000
title: "Miscellaneous"

5
html/routes/404.pug

@ -1,5 +0,0 @@
extends /bluetooth-class/html/templates/layout
block content
a(href="/") &lArr; Return to home page
p The file you are looking for doesn't exist here

7
html/routes/500.pug

@ -1,7 +0,0 @@
extends /bluetooth-class/html/templates/layout
block content
a(href="/") &lArr; Return to home page
p
| Something went wrong with this website.
| An alert has likely been sent to me, but an email is the fastest way to get bugs fixed and is greatly appreciated.

167
html/routes/index.pug

@ -1,167 +0,0 @@
extends /bluetooth-class/html/templates/layout
block content
// Project header and code result of the generated form below
h1 BlueTooth Class
p
a(href="https://www.systutorials.com/docs/linux/man/8-hciconfig/") hciconfig
| device identification command:
|
kbd
| hciconfig 0 class
|
span#bluetoothClass
// All available options for users to build a Bluetooth Class code from
-
const gridSizing = [
"uk-child-width-1-1",
"uk-child-width-1-2@s",
"uk-child-width-1-3@m",
"uk-child-width-1-4@l"
]
const codes = {
majorServices: {
"Information": 0x800000,
"Telephony": 0x400000,
"Audio": 0x200000,
"Transfer": 0x100000,
"Capturing": 0x080000,
"Rendering": 0x040000,
"Access point": 0x020000,
"Positioning": 0x010000,
"Limited discovery": 0x002000
},
majorDevices: {
"Uncategorized": 0x1F00,
"Toy": 0x0800,
"Wearable": 0x0700,
"Imaging": 0x0600,
"Peripheral": 0x0500,
"Media": 0x0400,
"Access point": 0x0300,
"Phone": 0x0200,
"Computer": 0x0100,
"Miscellaneous": 0x0000,
},
minorDevices: {
"Toy": {
"Game": 0x14,
"Controller": 0x10,
"Doll": 0x0C,
"Vehicle": 0x08,
"Robot": 0x04,
},
"Wearable": {
"Glasses": 0x14,
"Helmet": 0x10,
"Jacket": 0x0C,
"Pager": 0x08,
"Watch": 0x04,
},
"Imaging": {
"Display": 0x10,
"Camera": 0x20,
"Scanner": 0x40,
"Printer": 0x80,
},
"Peripheral": {
"Uncategorized": 0x00,
"Keyboard": 0x40,
"Pointer": 0x80,
"Joystick": 0x04,
"Gamepad": 0x08,
"Remote control": 0x0C,
"Sensor": 0x10,
"Digitizer": 0x14,
"Card reader": 0x18,
},
"Media": {
"Uncategorized": 0x00,
"Headset": 0x04,
"Microphone": 0x10,
"Loudspeaker": 0x14,
"Headphones": 0x18,
"Car audio": 0x20,
"Video camera": 0x30,
"Monitor": 0x38,
"Conferencing": 0x40,
},
"Access point": {
"Available": 0x00,
"1-17% use": 0x20, // Level 1
"17-33% use": 0x40, // Level 2
"33-50% use": 0x60, // Level 3
"50-67% use": 0x80, // Level 4
"67-83% use": 0xA0, // Level 5
"83-99% use": 0xC0, // Level 6
"Unavailable": 0xE0,
},
"Phone": {
"Uncategorized": 0x00,
"Cell": 0x04,
"Cordless": 0x08,
},
"Computer": {
"Uncategorized": 0x00,
"Desktop": 0x04,
"Server": 0x08,
"Laptop": 0x0C,
"PDA": 0x14,
"Watch": 0x18,
},
"Miscellaneous": {},
"Uncategorized": {}
}
}
// Input selections per group
h2 Major service
.uk-grid(class=gridSizing)
each value, key in codes.majorServices
div
label
input.uk-checkbox(
id="majorService"+key
type="checkbox"
value=value
)
| #{key}
h3 Major device
.uk-grid(class=gridSizing)
each value, key in codes.majorDevices
div
label
input.uk-radio(
id="majorDevice"+key
name="majorDevice"
type="radio"
value=value
)
| #{key}
h4 Minor device
.minor-devices
each devices, groupKey in codes.minorDevices
div.uk-grid(class=gridSizing class=groupKey)
each value, key in devices
div
label
input.uk-radio(
id="minorDevice"+groupKey+key
name="minorDevice"+groupKey
type="radio"
value=value
)
| #{key}
else
.uk-width-expand
span No options for this combination

5
html/routes/offline.pug

@ -1,5 +0,0 @@
extends /bluetooth-class/html/templates/layout
block content
a(href="/") &lArr; Return to home page
p Please check your Internet connection, your request could not be completed.

35
html/templates/layout.pug

@ -1,35 +0,0 @@
doctype html
html(lang="en")
head
meta(charset="utf-8")
meta(name="description" content="Builder for hcitool class codes")
meta(name="theme-color" content="#3B5998")
meta(name="viewport" content="width=device-width, initial-scale=1")
title BlueTooth Class
link(rel="shortcut icon" href="/favicon.ico")
link(rel="apple-touch-icon" href="/apple-touch-icon.png")
link(rel="stylesheet" href="/bluetooth-class.css")
link(rel="manifest" href="/manifest.json" crossorigin="use-credentials")
if release
script(src="/sentry.js" defer)
script(src="/bluetooth-class.js" defer)
body
.container
main
noscript This application requires JavaScript to run!
block content
footer
span
| Built by
|
a(href="https://mobiusk.com") MobiusK

65
layouts/_default/baseof.html

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Builder for hcitool class codes">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
BlueTooth Class
{{ with .Params.Title }} - {{ . }} {{ end }}
</title>
<link rel="shortcut icon" href="/favicon.ico">
{{ $scss := resources.Get "index.scss" }}
{{ $style := $scss | toCSS $.Site.Params.scss }}
{{ $ts := resources.Get "index.ts" }}
{{ $tsTranspiled := $ts | babel }}
{{ $script := $tsTranspiled | js.Build $.Site.Params.ts }}
{{ if $.Site.Params.fingerprint.enabled }}
{{ with $.Site.Params.fingerprint.algorithm }}
{{ $style = $style | fingerprint . }}
{{ $script = $script | fingerprint . }}
{{ end }}
{{ end }}
<link rel="stylesheet" href="{{ $style.RelPermalink }}">
{{ if $.Site.Params.sentry }}
{{ $sentry := resources.Get "sentry.ts" | babel | js.Build $.Site.Params.ts | fingerprint "md5" }}
<script src="{{ $sentry.RelPermalink }}" defer></script>
{{ end }}
<script src="{{ $script.RelPermalink }}" defer></script>
</head>
<body>
<div class="container">
<main>
<h1>BlueTooth Class</h1>
<noscript>
This application requires JavaScript to run.
</noscript>
{{ block "main" . }}{{ end }}
</main>
<footer>
<span>
Built by <a href="https://mobiusk.com">MobiusK</a>
</span>
</footer>
</div>
</body>
</html>

3
layouts/_default/single.html

@ -0,0 +1,3 @@
{{ define "main" }}
{{ .Content }}
{{ end }}

92
layouts/index.html

@ -0,0 +1,92 @@
{{ define "main" }}
<!-- Code result of the generated form below -->
<p>
<a href="https://www.systutorials.com/docs/linux/man/8-hciconfig/">hciconfig</a>
device identification command:
<kbd>
hciconfig 0 class <span id="bluetoothClass"></span>
</kbd>
</p>
<!-- Input selections per BlueTooth class group -->
<h2>Major service</h2>
<div class="uk-grid uk-child-width-1-1 uk-child-width-1-2@s uk-child-width-1-3@m uk-child-width-1-4@l">
{{ range .Site.Data.codes.majorServices }}
{{ range $key, $value := . }}
<div>
<label>
<input
class="uk-checkbox"
id="majorService-{{ $key }}"
type="checkbox"
value={{ $key }}
>
{{ $value }}
</label>
</div>
{{ end }}
{{ end }}
</div>
<h3>Major device</h3>
<div class="uk-grid uk-child-width-1-1 uk-child-width-1-2@s uk-child-width-1-3@m uk-child-width-1-4@l">
{{ range .Site.Data.codes.majorDevices }}
<div>
<label>
<input
class="uk-radio"
id="majorDevice-{{ .code }}"
name="majorDevice"
type="radio"
value={{ .code }}
>
{{ .title }}
</label>
</div>
{{ end }}
</div>
<h4>Minor device</h4>
<div class="minor-devices">
{{ range .Site.Data.codes.majorDevices }}
{{ $majorDevice := print "majorDevice-" .code }}
<div class="{{ $majorDevice }} uk-grid uk-child-width-1-1 uk-child-width-1-2@s uk-child-width-1-3@m uk-child-width-1-4@l">
{{ range .minorDevices }}
{{ range $key, $value := . }}
<div>
<label>
<input
class="uk-radio"
id="minorDevice-{{ $majorDevice }}-{{ $key }}"
name="minorDevice-{{ $majorDevice }}"
type="radio"
value={{ $key }}
>
{{ $value }}
</label>
</div>
{{ end }}
{{ else }}
<div class="uk-width-expand">
<span>
No options for this combination
</span>
</div>
{{ end }}
</div>
{{ end }}
</div>
{{ .Content }}
{{ end }}

42
scripts/service-worker.ts

@ -1,42 +0,0 @@
import { ServiceWorkerCache } from "shared/scripts/service-worker-cache";
/* eslint-disable @typescript-eslint/ban-ts-comment */
// Cache manipulator
const cache: ServiceWorkerCache = new ServiceWorkerCache("replaceAtBuildWithDate");
// @ts-ignore Install the service worker and cache any files for offline use
self.addEventListener("install", (event: InstallEvent) => event.waitUntil(
cache.initialize([
"/404.html",
"/bluetooth-class.css",
"/bluetooth-class.js",
"/favicon.ico",
"/icon.png",
"/index.html",
"/manifest.json",
"/offline.html",
"/robots.txt",
"/sentry.js"
]).then(() =>
// @ts-ignore New service workers require a tab close and re-open to activate without this
self.skipWaiting()
)
));
// @ts-ignore Activate the service worker and remove previous caches
self.addEventListener("activate", (event: ExtendableEvent) => event.waitUntil(
cache.deletePreviousCaching().then(() =>
// @ts-ignore New service workers can immediately take control over current service workers
self.clients.claim()
)
));
// @ts-ignore Response priority: Cache > Network > Offline message
self.addEventListener("fetch", (event: FetchEvent) => event.respondWith(
cache.fetchOrFallback(
event.request,
() => fetch(event.request),
() => cache.match("/offline.html")
)
));

0
assets/favicon.ico → static/favicon.ico

0
assets/icon.png → static/icon.png

Before

Width: 512  |  Height: 512  |  Size: 43 KiB

After

Width: 512  |  Height: 512  |  Size: 43 KiB

Loading…
Cancel
Save