Skip to content

Instantly share code, notes, and snippets.

View derpyherp's full-sized avatar

derpyherp

View GitHub Profile

Here's how to create custom fields for posts in Publii that function similarly to those in WordPress.

Adding a custom field

First, create an override folder for your theme. For example, if your website uses the Simple theme...

\Publii\sites\my-website\input\themes\simple

...the override folder would be:

addEventListener("fetch", event => {
event.respondWith(redirect(event.request))
})
//localized links to redirect to
const countryMap = {
US: "https://us.foobar.com",
GB: "https://gb.foobar.com",
DE: "https://de.foobar.com",
FR: "https://fr.foobar.com",
@derpyherp
derpyherp / javascript-banner-rotator.js
Created January 8, 2022 11:51
Very basic JavaScript banner rotator.
//probably want a window width of at least 468px to display a 468x60 banner
if (window.matchMedia("(min-width: 468px)").matches) {
var banner;
//the first number should equal the number of banners
switch(Math.floor((Math.random() * 3) + 1)) {
case 1:
banner = ["https://destination1.com", "https://destination1.com/banner.gif"];
break;
case 2:
banner = ["https://destination2.com", "https://destination2.com/banner.png"];
@derpyherp
derpyherp / #social-media-referers
Last active January 7, 2022 14:06
Show a custom message to social media visitors.
Show a custom message to visitors from social media in JavaScript.
Catches all those pesky subdomains like l.instagram.com and m.facebook.com.