Skip to content

Instantly share code, notes, and snippets.

/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
@rofe
rofe / mpfilter.js
Created May 21, 2024 14:06
filter mountpoints in inventory.json
/* eslint-disable no-console, header/header, import/no-extraneous-dependencies */
import fs from 'fs-extra';
function filter(filters) {
return (mp) => filters.every((f) => {
if (f.startsWith('-')) {
return !mp.includes(f.substring(1));
} else {
return mp.includes(f);
}
@rofe
rofe / using-placeholders.js
Last active February 21, 2024 14:35
placeholders
import { fetchPlaceholders } from '/scripts/aem.js';
// fetch placeholders from the 'en' folder
const placeholders = await fetchPlaceholders('en');
// retrieve the value for key 'foo'
const { foo } = placeholders;
@rofe
rofe / sidekick-special-view.js
Created July 29, 2023 16:48
sidekick custom view: scripts.js
(async () => {
try {
// get the resource URL from the url query parameter
const url = new URL(window.location.href).searchParams.get('url');
if (url) {
const res = await fetch(url);
if (res.ok) {
const text = await res.text();
const data = JSON.parse(text);
// do something with the data
@rofe
rofe / sidekick-special-view.html
Last active July 29, 2023 16:45
sidekick custom view: HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<!-- inherit base styles from sidekick (if desired) -->
<link rel="stylesheet" href="chrome-extension://ccfggkjabjahcjoljmgmklhpaccedipo/app.css">
<!-- add your own styles -->
<link rel="stylesheet" href="styles.css">
<!-- add your logic -->
<script src="script.js"></script>
</head>
@rofe
rofe / config-special-view.json
Last active July 29, 2023 16:52
sidekick custom view: config.json
{
"specialViews": [{
"title": "Better JSON Viewer",
"path": "**.json",
"viewer": "/tools/sidekick/better-json-viewer/index.html"
}]
}
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
{
"plugins": [
{
"id": "foo",
"title": "Foo",
"url": "/tools/sidekick/foo.html"
},
]
}
const foo = ({ detail }) => {
const sk = detail.data;
// your custom code from button.action goes here
};
const sk = document.querySelector('helix-sidekick');
if (sk) {
// sidekick already loaded
sk.addEventListener('custom:foo', foo);
} else {
{
"plugins": [
{
"id": "foo",
"title": "Foo",
"event": "foo"
}
]
}