Skip to content

Commit 7341aab

Browse files
committed
Initial commit
1 parent e07e87a commit 7341aab

7 files changed

Lines changed: 61 additions & 12 deletions

File tree

‎.eleventy.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
const markdownIt = require("markdown-it");
22

3+
function normalizePathPrefix(rawPathPrefix = "/") {
4+
if (!rawPathPrefix || rawPathPrefix === "/") {
5+
return "/";
6+
}
7+
return `/${rawPathPrefix.replace(/^\/+|\/+$/g, "")}/`;
8+
}
9+
310
module.exports = function (eleventyConfig) {
11+
const pathPrefix = normalizePathPrefix(process.env.ELEVENTY_PATH_PREFIX);
12+
const pathPrefixWithoutTrailingSlash = pathPrefix === "/"
13+
? "/"
14+
: pathPrefix.slice(0, -1);
15+
const pathPrefixKey = pathPrefix.replace(/^\/|\/$/g, "");
16+
417
const md = markdownIt({
518
html: true,
619
breaks: false,
@@ -56,7 +69,23 @@ module.exports = function (eleventyConfig) {
5669
liveReload: true,
5770
});
5871

72+
eleventyConfig.addTransform("prefixRootRelativeUrls", function (content, outputPath) {
73+
const currentOutputPath = outputPath || this?.page?.outputPath || this?.outputPath;
74+
75+
if (!currentOutputPath || !currentOutputPath.endsWith(".html") || pathPrefix === "/") {
76+
return content;
77+
}
78+
79+
return content.replace(/\b(href|src|poster)=("|')\/(?!\/)([^"']*)\2/g, (match, attr, quote, targetPath) => {
80+
if (targetPath === pathPrefixKey || targetPath.startsWith(`${pathPrefixKey}/`)) {
81+
return match;
82+
}
83+
return `${attr}=${quote}${pathPrefixWithoutTrailingSlash}/${targetPath}${quote}`;
84+
});
85+
});
86+
5987
return {
88+
pathPrefix,
6089
dir: {
6190
input: ".",
6291
output: "_site",

‎.github/workflows/ci.yml‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ jobs:
1919
node-version: 20
2020
cache: npm
2121

22+
- name: Set Eleventy path prefix
23+
run: |
24+
REPO_NAME="${GITHUB_REPOSITORY#*/}"
25+
if [[ "$REPO_NAME" == *.github.io ]]; then
26+
echo "ELEVENTY_PATH_PREFIX=/" >> "$GITHUB_ENV"
27+
else
28+
echo "ELEVENTY_PATH_PREFIX=/${REPO_NAME}/" >> "$GITHUB_ENV"
29+
fi
30+
2231
- run: npm ci
23-
- run: npm run build
32+
- run: npm run build:css
33+
- run: npx eleventy --pathprefix="$ELEVENTY_PATH_PREFIX"
2434
- run: npm run check

‎.github/workflows/deploy.yml‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ jobs:
2525
node-version: 20
2626
cache: npm
2727

28+
- name: Set Eleventy path prefix
29+
run: |
30+
REPO_NAME="${GITHUB_REPOSITORY#*/}"
31+
if [[ "$REPO_NAME" == *.github.io ]]; then
32+
echo "ELEVENTY_PATH_PREFIX=/" >> "$GITHUB_ENV"
33+
else
34+
echo "ELEVENTY_PATH_PREFIX=/${REPO_NAME}/" >> "$GITHUB_ENV"
35+
fi
36+
2837
- run: npm ci
29-
- run: npm run build
38+
- run: npm run build:css
39+
- run: npx eleventy --pathprefix="$ELEVENTY_PATH_PREFIX"
3040
- run: npm run check
3141

3242
- uses: actions/upload-pages-artifact@v3

‎_includes/head.njk‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
<meta name="twitter:description" content="{{ pageDescription }}">
4343
<meta name="twitter:image" content="{{ site.url }}/img/logos/logo-belajarpython-square.png">
4444

45-
<link rel="icon" href="/img/favicon.png">
46-
<link rel="apple-touch-icon" href="/img/favicon.png">
45+
<link rel="icon" href="{{ '/img/favicon.png' | url }}">
46+
<link rel="apple-touch-icon" href="{{ '/img/favicon.png' | url }}">
4747
<meta name="theme-color" content="#2a5880">
4848
<meta name="msapplication-TileColor" content="#2a5880">
4949
<meta name="msvalidate.01" content="8CFBF57F61ECFF6C84740E37B7FCDE15">
5050

51-
<link rel="stylesheet" type="text/css" href="/css/base.css?v={{ site.version }}">
51+
<link rel="stylesheet" type="text/css" href="{{ '/css/base.css' | url }}?v={{ site.version }}">
5252
{% if useBrandIconFont %}
5353
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.7.2/css/all.min.css">
5454
{% endif %}

‎_includes/navbar.njk‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
</svg>
1111
</button>
1212
{% endif %}
13-
<a href="/" class="z-10">
14-
<img class="h-10 pt-1" src="/img/logo-belajarpython-140.png" alt="logo-belajarpython"/>
13+
<a href="{{ '/' | url }}" class="z-10">
14+
<img class="h-10 pt-1" src="{{ '/img/logo-belajarpython-140.png' | url }}" alt="logo-belajarpython"/>
1515
</a>
1616
<div class="hidden md:flex items-center justify-end">
1717
<div class="mr-5 flex gap-5">
18-
<a class="text-white text-opacity-70 hover:text-opacity-100" href="/tutorial/what-is-python">Tutorial</a>
18+
<a class="text-white text-opacity-70 hover:text-opacity-100" href="{{ '/tutorial/what-is-python/' | url }}">Tutorial</a>
1919
</div>
2020
<a
2121
class="flex h-9 items-center rounded-full bg-gradient-to-l from-secondary-500 to-secondary-400 px-7 text-sm text-black"
2222
href="https://github.com/belajarpythoncom/belajarpython.com">
2323
<span class="-mt-0.5">Join on Github</span>
24-
<img class="ml-2 h-4 button-github-yellow-img" src="/img/icon-github.svg"/>
24+
<img class="ml-2 h-4 button-github-yellow-img" src="{{ '/img/icon-github.svg' | url }}"/>
2525
</a>
2626
</div>
2727
</div>

‎_includes/python-runner.njk‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
header.className = 'code-runner-header';
276276
header.innerHTML = `
277277
<div class="code-runner-title">
278-
<img src="/img/icons/icon-python.ico" width="20" height="20" alt="Logo Python" style="display: block;">
278+
<img src="{{ '/img/icons/icon-python.ico' | url }}" width="20" height="20" alt="Logo Python" style="display: block;">
279279
<span>Interactive Python <span class="hidden md:inline">Editor</span></span>
280280
</div>
281281
<div class="code-runner-actions">

‎tools/online-python-ide.njk‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ permalink: /online-python-ide/
1313
</div>
1414

1515
<div class="h-8 flex items-center px-4 gap-4 text-xs select-none text-slate-300">
16-
<img src="/img/icons/icon-python.ico" class="w-4 h-4" alt="Icon">
16+
<img src="{{ '/img/icons/icon-python.ico' | url }}" class="w-4 h-4" alt="Icon">
1717
<span class="hover:bg-white/10 px-2 py-0.5 rounded cursor-pointer transition-colors">File</span>
1818
<span class="hover:bg-white/10 px-2 py-0.5 rounded cursor-pointer transition-colors">Edit</span>
1919
<span class="hover:bg-white/10 px-2 py-0.5 rounded cursor-pointer transition-colors">Selection</span>
@@ -59,7 +59,7 @@ permalink: /online-python-ide/
5959
<!-- Tabs -->
6060
<div class="h-9 bg-[#2d2d2d] flex items-center no-scrollbar overflow-x-auto">
6161
<div class="bg-[#1e1e1e] h-full flex items-center px-3 border-t-2 border-blue-500 text-white min-w-fit gap-2 text-xs">
62-
<img src="/img/icons/icon-python.ico" class="w-3 h-3"> app.py
62+
<img src="{{ '/img/icons/icon-python.ico' | url }}" class="w-3 h-3"> app.py
6363
<span class="hover:bg-slate-700 rounded-sm p-0.5 cursor-pointer ml-2">×</span>
6464
</div>
6565
</div>

0 commit comments

Comments
 (0)