Skip to content

Commit f4cb2f0

Browse files
authored
Simplify the output by using the new css aspect ratio (#33)
* refactor(*): split in folders * feat(editing): support new aspect-ratio * refactor(build): move to esbuild (obsidian example) * refactor: run linting
1 parent 9d77b0d commit f4cb2f0

22 files changed

+1436
-372
lines changed

.eslintignor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
npm node_modules
2+
build

.eslintrc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": [
5+
"@typescript-eslint"
6+
],
7+
"extends": [
8+
"eslint:recommended",
9+
],
10+
"parserOptions": {
11+
"sourceType": "module"
12+
},
13+
"rules": {
14+
"no-unused-vars": "off",
15+
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
16+
"@typescript-eslint/ban-ts-comment": "off",
17+
"no-prototype-builtins": "off",
18+
"@typescript-eslint/no-empty-function": "off"
19+
} ,
20+
"overrides": [
21+
{
22+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
23+
"parser": "@typescript-eslint/parser",
24+
"plugins": ["@typescript-eslint"],
25+
"extends": [
26+
"eslint:recommended",
27+
"plugin:@typescript-eslint/eslint-recommended",
28+
"plugin:@typescript-eslint/recommended",
29+
"prettier" // Has to be last. Turns off eslint rules conflicting with prettier
30+
]
31+
}
32+
]
33+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ To install this plugin, download zip archive from GitHub releases page. Extract
1818

1919
# Change log
2020

21+
## 0.3.0
22+
- Simplify the output when using a recent Obsidian download, by leveraging `aspect-ratio` css.
23+
2124
## 0.2.0
2225
- Update: the keybinding from `Mode + Shift + I` to `Alt + I` ([Issue 4](https://github.com/FHachez/obsidian-convert-url-to-iframe/issues/4))
2326
- Only output the app name in the console ([Issue 3](https://github.com/FHachez/obsidian-convert-url-to-iframe/issues/3))

configure_iframe_modal.ts

Lines changed: 0 additions & 165 deletions
This file was deleted.

esbuild.config.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import esbuild from "esbuild";
2+
import process from "process";
3+
import builtins from 'builtin-modules'
4+
5+
const banner =
6+
`/*
7+
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
8+
if you want to view the source, please visit the github repository of this plugin
9+
*/
10+
`;
11+
12+
const prod = (process.argv[2] === 'production');
13+
14+
esbuild.build({
15+
banner: {
16+
js: banner,
17+
},
18+
entryPoints: ['src/main.ts'],
19+
bundle: true,
20+
external: ['obsidian', 'electron', ...builtins],
21+
format: 'cjs',
22+
watch: !prod,
23+
target: 'es2016',
24+
logLevel: "info",
25+
sourcemap: prod ? false : 'inline',
26+
treeShaking: true,
27+
outfile: 'main.js',
28+
}).catch(() => process.exit(1));

iframe_converter.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +0,0 @@
1-
2-
3-
export function updateUrlIfYoutube(url: string) {
4-
// Youtube url format:
5-
// - youtube.com/.../?...&v=[Video Id]
6-
// - youtu.com/[Video Id]
7-
// - youtube.com/embed => don't do anything it's already an embed link
8-
const youtubeIdRegex = /(youtube(?<top_domain1>(\.\w{2,3}){1,2})\/([^\/]+\/.+\/|.*[?&]v=)|youtu(?<top_domain2>(\.\w{2,3}){1,2})\/)(?<id>[a-zA-Z0-9_-]{11})/gi;
9-
const id = youtubeIdRegex.exec(url)
10-
11-
if (id) {
12-
const urlParameterMatches = url.match(/\?([^&]+)/);
13-
const urlParameters = new URLSearchParams(
14-
urlParameterMatches ? urlParameterMatches[0] : ''
15-
)
16-
17-
// We need to remove the `v` parameter which contains the video id since we put it in the url
18-
urlParameters.delete('v')
19-
20-
if (urlParameters.has('t')) {
21-
urlParameters.set('start', urlParameters.get('t'));
22-
urlParameters.delete('t')
23-
}
24-
25-
const parameters = urlParameters.toString().length > 0 ? `?${urlParameters.toString()}` : '';
26-
const topDomain = id.groups['top_domain1'] || id.groups['top_domain2'] || ".com";
27-
28-
return `https://www.youtube${topDomain}/embed/${id.groups['id']}${parameters}`;
29-
}
30-
return url;
31-
}
32-
33-
export function isUrl(text: string): boolean {
34-
const urlRegex = new RegExp(
35-
"^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$"
36-
);
37-
return urlRegex.test(text);
38-
}

libs/oembed.ts

Whitespace-only changes.

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "convert-url-to-iframe",
33
"name": "Convert url to preview (iframe)",
4-
"version": "0.2.0",
4+
"version": "0.3.0",
55
"description": "Convert an url (ex, youtube) into an iframe (preview)",
66
"author": "Hachez Floran",
77
"authorUrl": "https://github.com/FHachez",

0 commit comments

Comments
 (0)