Use Prettier to format files

This commit is contained in:
Nikita Karamov 2021-08-14 19:12:42 +02:00
parent 55c1e677e0
commit 67808803a4
No known key found for this signature in database
GPG key ID: 7FCADEDBB1AEBE44
8 changed files with 68 additions and 64 deletions

2
.prettierignore Normal file
View file

@ -0,0 +1,2 @@
dist
*.md

1
.prettierrc.json Normal file
View file

@ -0,0 +1 @@
{}

View file

@ -1,42 +1,41 @@
const gulp = require('gulp'); const gulp = require("gulp");
const postcss = require('gulp-postcss'); const postcss = require("gulp-postcss");
const sass = require('gulp-sass')(require('sass')); const sass = require("gulp-sass")(require("sass"));
const sourcemaps = require('gulp-sourcemaps'); const sourcemaps = require("gulp-sourcemaps");
const terser = require('gulp-terser'); const terser = require("gulp-terser");
function html() { function html() {
return gulp.src('./src/index.html') return gulp.src("./src/index.html").pipe(gulp.dest("./dist/"));
.pipe(gulp.dest('./dist/'));
} }
function css() { function css() {
return gulp.src('./src/scss/*.scss') return gulp
.src("./src/scss/*.scss")
.pipe(sourcemaps.init()) .pipe(sourcemaps.init())
.pipe(sass.sync().on('error', sass.logError)) .pipe(sass.sync().on("error", sass.logError))
.pipe(postcss([require("autoprefixer"), require("postcss-csso")])) .pipe(postcss([require("autoprefixer"), require("postcss-csso")]))
.pipe(sourcemaps.write('.')) .pipe(sourcemaps.write("."))
.pipe(gulp.dest('./dist/')); .pipe(gulp.dest("./dist/"));
} }
function js() { function js() {
return gulp.src('./src/main.js') return gulp
.src("./src/main.js")
.pipe(sourcemaps.init()) .pipe(sourcemaps.init())
.pipe(terser({ ecma: 5 })) .pipe(terser({ ecma: 5 }))
.pipe(sourcemaps.write('.')) .pipe(sourcemaps.write("."))
.pipe(gulp.dest('./dist/')); .pipe(gulp.dest("./dist/"));
} }
function static() { function static() {
return gulp.src('./src/static/**/*') return gulp.src("./src/static/**/*").pipe(gulp.dest("./dist/"));
.pipe(gulp.dest('./dist/'));
} }
exports.default = gulp.parallel(html, css, js, static); exports.default = gulp.parallel(html, css, js, static);
exports.watch = () => { exports.watch = () => {
gulp.watch('./src/index.pug', html); gulp.watch("./src/index.pug", html);
gulp.watch('./src/style/*.scss', css); gulp.watch("./src/style/*.scss", css);
gulp.watch('./src/script/index.js', js); gulp.watch("./src/script/index.js", js);
gulp.watch('./src/static/*', static); gulp.watch("./src/static/*", static);
} };

View file

@ -6,9 +6,9 @@
"author": "Nikita Karamov <nick@karamoff.dev>", "author": "Nikita Karamov <nick@karamoff.dev>",
"homepage": "https://toot.karamoff.dev/", "homepage": "https://toot.karamoff.dev/",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/NickKaramoff/toot.git" "url": "https://github.com/NickKaramoff/toot.git"
}, },
"private": true, "private": true,
"scripts": { "scripts": {
"build": "gulp", "build": "gulp",
@ -25,6 +25,7 @@
"gulp-terser": "^2.0.1", "gulp-terser": "^2.0.1",
"postcss": "^8.2.15", "postcss": "^8.2.15",
"postcss-csso": "^5.0.1", "postcss-csso": "^5.0.1",
"prettier": "2.3.2",
"sass": "^1.37.5", "sass": "^1.37.5",
"sirv-cli": "^1.0.10" "sirv-cli": "^1.0.10"
}, },

View file

@ -20,32 +20,30 @@ function normalizeUrl(url) {
if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1) { if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1) {
url = "https://" + url; url = "https://" + url;
} }
if (url.charAt(url.length - 1) !== '/'){ if (url.charAt(url.length - 1) !== "/") {
url = url + "/"; url = url + "/";
} }
return url; return url;
} }
const instance = document.getElementById('instance'); const instance = document.getElementById("instance");
const instances_list = document.getElementById('instances_list'); const instances_list = document.getElementById("instances_list");
var prefillInstance = window.localStorage.getItem('mastodon_instance'); var prefillInstance = window.localStorage.getItem("mastodon_instance");
var paramPairs = window.location.search.substr(1).split('&'); var paramPairs = window.location.search.substr(1).split("&");
var paramPairsLength = paramPairs.length; var paramPairsLength = paramPairs.length;
for (var i = 0; i < paramPairsLength; i++) { for (var i = 0; i < paramPairsLength; i++) {
var paramPair = paramPairs[i].split('='); var paramPair = paramPairs[i].split("=");
if (paramPair[0] === 'text') { if (paramPair[0] === "text") {
document.getElementById('text').value = decodeURIComponent(paramPair[1]); document.getElementById("text").value = decodeURIComponent(paramPair[1]);
} else if (paramPair[0] === 'instance') { } else if (paramPair[0] === "instance") {
prefillInstance = decodeURIComponent(paramPair[1]); prefillInstance = decodeURIComponent(paramPair[1]);
} }
} }
delete i
delete paramPair
function instances_loading_error() { function instances_loading_error() {
console.error('Failed to fetch servers list from joinmastodon.'); console.error("Failed to fetch servers list from joinmastodon.");
} }
function instances_loaded() { function instances_loaded() {
@ -57,14 +55,14 @@ function instances_loaded() {
const servers = JSON.parse(this.responseText); const servers = JSON.parse(this.responseText);
const chosen_instance = instance.value; const chosen_instance = instance.value;
const domains = servers.map(obj => obj.domain); const domains = servers.map((obj) => obj.domain);
if (chosen_instance && domains.indexOf(chosen_instance) === -1) { if (chosen_instance && domains.indexOf(chosen_instance) === -1) {
domains.push(chosen_instance); domains.push(chosen_instance);
} }
domains.sort(); domains.sort();
for (const domain of domains) { for (const domain of domains) {
const opt = document.createElement('option'); const opt = document.createElement("option");
opt.value = normalizeUrl(domain); opt.value = normalizeUrl(domain);
instances_list.appendChild(opt); instances_list.appendChild(opt);
} }
@ -74,28 +72,26 @@ if (prefillInstance != null) {
instance.value = normalizeUrl(prefillInstance); instance.value = normalizeUrl(prefillInstance);
} }
instance.addEventListener('focus', function (e) { instance.addEventListener("focus", function (e) {
if (instances_list.children.length === 0) { if (instances_list.children.length === 0) {
const req = new XMLHttpRequest(); const req = new XMLHttpRequest();
req.addEventListener('load', instances_loaded); req.addEventListener("load", instances_loaded);
req.addEventListener('error', instances_loading_error); req.addEventListener("error", instances_loading_error);
req.open('GET', 'https://api.joinmastodon.org/servers'); req.open("GET", "https://api.joinmastodon.org/servers");
req.send(); req.send();
} }
}) });
document document.getElementById("form").addEventListener("submit", function (e) {
.getElementById('form') e.preventDefault();
.addEventListener('submit', function (e) { var text = e.target.elements["text"].value;
e.preventDefault(); var instance = normalizeUrl(e.target.elements["instance"].value);
var text = e.target.elements['text'].value; var remember = e.target.elements["remember"].checked;
var instance = normalizeUrl(e.target.elements['instance'].value);
var remember = e.target.elements['remember'].checked;
if (remember) { if (remember) {
window.localStorage.setItem('mastodon_instance', instance); window.localStorage.setItem("mastodon_instance", instance);
} }
var shareUrl = instance + "share?text=" + encodeURIComponent(text); var shareUrl = instance + "share?text=" + encodeURIComponent(text);
window.location.href = shareUrl; window.location.href = shareUrl;
}) });

View file

@ -16,11 +16,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
$text-font: 'Roboto', sans-serif; $text-font: "Roboto", sans-serif;
$bg: #1F232B; $bg: #1f232b;
$text: #9baec8; $text: #9baec8;
$title:#d9e1e8; $title: #d9e1e8;
$button-bg: #2b90d9; $button-bg: #2b90d9;
$button-hover-bg: #56a7e1; $button-hover-bg: #56a7e1;

View file

@ -101,11 +101,11 @@ main {
font-size: 1rem; font-size: 1rem;
border-radius: 4px; border-radius: 4px;
&[type=checkbox] { &[type="checkbox"] {
margin-right: 8px; margin-right: 8px;
} }
&[type=submit] { &[type="submit"] {
display: inline-block; display: inline-block;
text-align: center; text-align: center;
background-color: $button-bg; background-color: $button-bg;
@ -127,7 +127,7 @@ main {
} }
textarea, textarea,
input[type=url] { input[type="url"] {
color: inherit; color: inherit;
width: 100%; width: 100%;
outline: 0; outline: 0;
@ -162,7 +162,7 @@ footer {
flex-wrap: wrap; flex-wrap: wrap;
section { section {
margin: .5rem 1rem; margin: 0.5rem 1rem;
a { a {
color: inherit; color: inherit;

View file

@ -2101,6 +2101,11 @@ postcss@^8.2.15:
nanoid "^3.1.23" nanoid "^3.1.23"
source-map-js "^0.6.2" source-map-js "^0.6.2"
prettier@2.3.2:
version "2.3.2"
resolved "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d"
integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
pretty-hrtime@^1.0.0: pretty-hrtime@^1.0.0:
version "1.0.3" version "1.0.3"
resolved "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1" resolved "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1"