Use Prettier to format files
This commit is contained in:
parent
55c1e677e0
commit
67808803a4
8 changed files with 68 additions and 64 deletions
2
.prettierignore
Normal file
2
.prettierignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
dist
|
||||
*.md
|
1
.prettierrc.json
Normal file
1
.prettierrc.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
43
gulpfile.js
43
gulpfile.js
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
"author": "Nikita Karamov <nick@karamoff.dev>",
|
||||
"homepage": "https://toot.karamoff.dev/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/NickKaramoff/toot.git"
|
||||
},
|
||||
"type": "git",
|
||||
"url": "https://github.com/NickKaramoff/toot.git"
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "gulp",
|
||||
|
@ -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"
|
||||
},
|
||||
|
|
60
src/main.js
60
src/main.js
|
@ -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) {
|
||||
e.preventDefault();
|
||||
var text = e.target.elements['text'].value;
|
||||
var instance = normalizeUrl(e.target.elements['instance'].value);
|
||||
var remember = e.target.elements['remember'].checked;
|
||||
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;
|
||||
|
||||
if (remember) {
|
||||
window.localStorage.setItem('mastodon_instance', instance);
|
||||
}
|
||||
if (remember) {
|
||||
window.localStorage.setItem("mastodon_instance", instance);
|
||||
}
|
||||
|
||||
var shareUrl = instance + "share?text=" + encodeURIComponent(text);
|
||||
window.location.href = shareUrl;
|
||||
})
|
||||
var shareUrl = instance + "share?text=" + encodeURIComponent(text);
|
||||
window.location.href = shareUrl;
|
||||
});
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
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;
|
||||
$title: #d9e1e8;
|
||||
|
||||
$button-bg: #2b90d9;
|
||||
$button-hover-bg: #56a7e1;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Reference in a new issue