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 postcss = require('gulp-postcss');
const sass = require('gulp-sass')(require('sass'));
const sourcemaps = require('gulp-sourcemaps');
const terser = require('gulp-terser');
const gulp = require("gulp");
const postcss = require("gulp-postcss");
const sass = require("gulp-sass")(require("sass"));
const sourcemaps = require("gulp-sourcemaps");
const terser = require("gulp-terser");
function html() {
return gulp.src('./src/index.html')
.pipe(gulp.dest('./dist/'));
return gulp.src("./src/index.html").pipe(gulp.dest("./dist/"));
}
function css() {
return gulp.src('./src/scss/*.scss')
return gulp
.src("./src/scss/*.scss")
.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(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/'));
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("./dist/"));
}
function js() {
return gulp.src('./src/main.js')
return gulp
.src("./src/main.js")
.pipe(sourcemaps.init())
.pipe(terser({ ecma: 5 }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/'));
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("./dist/"));
}
function static() {
return gulp.src('./src/static/**/*')
.pipe(gulp.dest('./dist/'));
return gulp.src("./src/static/**/*").pipe(gulp.dest("./dist/"));
}
exports.default = gulp.parallel(html, css, js, static);
exports.watch = () => {
gulp.watch('./src/index.pug', html);
gulp.watch('./src/style/*.scss', css);
gulp.watch('./src/script/index.js', js);
gulp.watch('./src/static/*', static);
}
gulp.watch("./src/index.pug", html);
gulp.watch("./src/style/*.scss", css);
gulp.watch("./src/script/index.js", js);
gulp.watch("./src/static/*", static);
};

View file

@ -25,6 +25,7 @@
"gulp-terser": "^2.0.1",
"postcss": "^8.2.15",
"postcss-csso": "^5.0.1",
"prettier": "2.3.2",
"sass": "^1.37.5",
"sirv-cli": "^1.0.10"
},

View file

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

View file

@ -16,9 +16,9 @@
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;
$title: #d9e1e8;

View file

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

View file

@ -2101,6 +2101,11 @@ postcss@^8.2.15:
nanoid "^3.1.23"
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:
version "1.0.3"
resolved "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1"