diff --git a/config/filters/general.js b/config/filters/general.js index 9793ecc..403f11f 100644 --- a/config/filters/general.js +++ b/config/filters/general.js @@ -38,4 +38,5 @@ export default { return `${string}s${trailing ? `${trailing}` : ''}`; }, jsonEscape: (string) => JSON.stringify(string), + regexEscape: (string) => string.replace(/[.*+?^${}()[]\\]/g, '\\$&') }; diff --git a/config/plugins/html-config.js b/config/plugins/html-config.js index 7595846..b20baf5 100644 --- a/config/plugins/html-config.js +++ b/config/plugins/html-config.js @@ -2,7 +2,7 @@ import htmlmin from 'html-minifier-terser'; export const htmlConfig = (eleventyConfig) => { eleventyConfig.addTransform('html-minify', (content, path) => { - if (path && (path.endsWith('.html') || path.endsWith('.php'))) { + if (path && (path.endsWith('.html') || path.endsWith('.php') && !path.includes("api"))) { return htmlmin.minify(content, { collapseBooleanAttributes: true, collapseWhitespace: true, diff --git a/package-lock.json b/package-lock.json index d5b5b5e..a524fe3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "8.1.9", + "version": "8.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "8.1.9", + "version": "8.2.0", "license": "MIT", "dependencies": { "minisearch": "^7.1.2", diff --git a/package.json b/package.json index 816256d..5ed68aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "8.1.9", + "version": "8.2.0", "description": "The source for my personal site. Built using 11ty (and other tools).", "type": "module", "engines": { diff --git a/src/meta/bots.php.liquid b/src/meta/bots.php.liquid new file mode 100644 index 0000000..4f50af5 --- /dev/null +++ b/src/meta/bots.php.liquid @@ -0,0 +1,48 @@ +--- +permalink: "/api/bots.php" +layout: null +eleventyExcludeFromCollections: true +excludeFromSitemap: true +--- + {% endfor %} -{%- assign userAgents = "" -%} -{% for robot in robots -%} - {%- for userAgent in robot.user_agents -%} - {%- if userAgent != "*" and userAgent != "NaN" -%} - {%- assign userAgents = userAgents | append: userAgent %} - {%- unless forloop.last -%} - {%- assign userAgents = userAgents | append: "|" -%} - {%- endunless -%} +{%- assign escapedAgents = "" -%} +{%- for robot in robots -%} + {%- for agent in robot.user_agents -%} + {%- if agent != "*" and agent != "NaN" -%} + {%- assign escaped = agent | regexEscape -%} + {%- assign escapedAgents = escapedAgents | append: escaped | append: "|" -%} {%- endif -%} {%- endfor -%} -{%- endfor %} -{% if userAgents != "" or referers != "" -%} -RewriteCond %{HTTP_USER_AGENT} "{{ userAgents }}" [NC] +{%- endfor -%} +{%- assign userAgentsRegex = escapedAgents | slice: 0, escapedAgents.size | rstrip: "|" -%} +{% if userAgentsRegex != "" %} +RewriteEngine On +RewriteCond %{HTTP_USER_AGENT} "{{ userAgentsRegex }}" [NC] RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC] -RewriteRule .* /403/index.html [L,R=403] -{%- endif %} - +RewriteRule .* /api/bots.php [L] +{% endif %} AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json