Skip to content

Commit

Permalink
Inject vendor.js via loader
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1eef committed Aug 30, 2024
1 parent 94aaa6e commit 07788b4
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/typescript/postman/src/postman/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
const { href } = item;
return fetch(href, options)
.then((res) => res.text())
.then((text) => ({ type: 'application/javascript', text }))
.then((text) => ({ type: 'application/javascript', text, ...item.props }))
.then((props) => Object.assign(document.createElement('script'), props));
},

Expand Down
1 change: 0 additions & 1 deletion src/html/main/random.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<%= erb("_favicon.html.erb") %>
</head>
<body>
<script src="/js/main/vendor.js?v=<%= commit %>"></script>
<script src="/js/main/random.js?v=<%= commit %>"></script>
</body>
</html>
1 change: 0 additions & 1 deletion src/html/main/redirect.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<%= erb("_favicon.html.erb") %>
</head>
<body>
<script src="/js/main/vendor.js?v=<%= commit %>"></script>
<script src="/js/main/redirect.js?v=<%= commit %>"></script>
</body>
</html>
1 change: 0 additions & 1 deletion src/html/main/surah-index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<body>
<%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %>
<div class="root h-full"></div>
<script src="/js/main/vendor.js?v=<%= commit %>"></script>
<script src="/js/loaders/surah-index-loader.js?v=<%= commit %>"></script>
</body>
</html>
1 change: 0 additions & 1 deletion src/html/main/surah-stream.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
data-surah-id="<%= context.surah.id %>"
data-audio-base-url="<%= audio_base_url %>">
</div>
<script src="/js/main/vendor.js?v=<%= commit %>"></script>
<script src="/js/loaders/surah-stream-loader.js?v=<%= commit %>"></script>
</body>
</html>
11 changes: 7 additions & 4 deletions src/js/loaders/SurahIndexLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { formatNumber } from "~/lib/t";
const progressBar: HTMLProgressElement = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
postman(
item.script(`/js/main/surah-index.js?v=${rev}`),
item.script(`/js/main/vendor.js?v=${rev}`, { id: 0 }),
item.script(`/js/main/surah-index.js?v=${rev}`, { id: 1 }),
item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"),
item.font("Mada Regular", "url(/fonts/mada-regular.ttf"),
item.progress((percent: number) => {
Expand All @@ -34,8 +35,10 @@ import { formatNumber } from "~/lib/t";
[loader, style].forEach((el) => el.remove());
pkg.fonts.forEach((f) => document.fonts.add(f));
pkg.css.forEach((s) => document.head.appendChild(s));
pkg.scripts.forEach((s) =>
document.body.removeChild(document.body.appendChild(s)),
);
pkg.scripts
.sort((s) => s.id)
.forEach((s) => {
document.body.removeChild(document.body.appendChild(s));
});
});
})();
11 changes: 7 additions & 4 deletions src/js/loaders/SurahStreamLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { formatNumber } from "~/lib/t";
const progressBar = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
postman(
item.script(`/js/main/surah-stream.js?v=${rev}`),
item.script(`/js/main/vendor.js?v=${rev}`, { id: 0 }),
item.script(`/js/main/surah-stream.js?v=${rev}`, { id: 1 }),
item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"),
item.font("Mada Regular", "url(/fonts/mada-regular.ttf"),
/* eslint-disable */
Expand All @@ -41,8 +42,10 @@ import { formatNumber } from "~/lib/t";
pkg.fonts.forEach((f) => document.fonts.add(f));
pkg.css.forEach((s) => document.head.appendChild(s));
pkg.json.forEach((o) => document.body.appendChild(o));
pkg.scripts.forEach((s) =>
document.body.removeChild(document.body.appendChild(s)),
);
pkg.scripts
.sort((s) => s.id)
.forEach((s) => {
document.body.removeChild(document.body.appendChild(s));
});
});
})();
5 changes: 1 addition & 4 deletions src/js/main/surah-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ import { SurahIndex } from "~/components/SurahIndex";
(e: TSurah) => new Surah(e),
);

render(
<SurahIndex locale={locale} surahs={surahs} t={t} />,
root
);
render(<SurahIndex locale={locale} surahs={surahs} t={t} />, root);
})();
5 changes: 1 addition & 4 deletions src/js/main/surah-stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,5 @@ import { SurahStream } from "~/components/SurahStream";
ayah.ms = ms * 1000;
}

render(
<SurahStream surah={surah} locale={locale} t={t} />,
root
);
render(<SurahStream surah={surah} locale={locale} t={t} />, root);
})();

0 comments on commit 07788b4

Please sign in to comment.