mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Make module fonts relative
This commit is contained in:
parent
54dad896b3
commit
3894b485df
1 changed files with 18 additions and 4 deletions
22
.eleventy.js
22
.eleventy.js
|
|
@ -1,9 +1,9 @@
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import replace_css_url from 'replace-css-url'
|
||||||
|
import { InlineCodeManager } from '@11ty/eleventy-assets'
|
||||||
|
|
||||||
import nuxtConfig from './nuxt.config'
|
import nuxtConfig from './nuxt.config'
|
||||||
|
|
||||||
import { InlineCodeManager } from '@11ty/eleventy-assets'
|
|
||||||
|
|
||||||
|
|
||||||
function getAssetFilePath(componentName) {
|
function getAssetFilePath(componentName) {
|
||||||
return `./${componentName}`
|
return `./${componentName}`
|
||||||
|
|
@ -42,9 +42,17 @@ module.exports = function ( eleventyConfig ) {
|
||||||
if(!cssManager.hasComponentCode(componentName)) {
|
if(!cssManager.hasComponentCode(componentName)) {
|
||||||
const fileContents = fs.readFileSync(getAssetFilePath(componentName), { encoding: "UTF-8" })
|
const fileContents = fs.readFileSync(getAssetFilePath(componentName), { encoding: "UTF-8" })
|
||||||
|
|
||||||
// console.log('Got component', componentName, componentCss)
|
// Replace urls in css with relative urls for dist folder
|
||||||
|
const parsedCss = replace_css_url(
|
||||||
|
fileContents,
|
||||||
|
function( path ) {
|
||||||
|
const fileName = path.split('/').pop().split('#')[0].split('?')[0]
|
||||||
|
|
||||||
cssManager.addComponentCode(componentName, fileContents)
|
return '/fonts/' + fileName
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
cssManager.addComponentCode(componentName, parsedCss)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log usage for this url
|
// Log usage for this url
|
||||||
|
|
@ -55,6 +63,12 @@ module.exports = function ( eleventyConfig ) {
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// Copy Inter font files
|
||||||
|
eleventyConfig.addPassthroughCopy({
|
||||||
|
"node_modules/@fontsource/inter/**/*.woff2": "fonts"
|
||||||
|
})
|
||||||
|
|
||||||
// This needs to be called in a Layout template.
|
// This needs to be called in a Layout template.
|
||||||
eleventyConfig.addJavaScriptFunction('getJs', function ( url = this.page.url ) {
|
eleventyConfig.addJavaScriptFunction('getJs', function ( url = this.page.url ) {
|
||||||
// console.log( 'jsManager.getCodeForUrl(url)', url )
|
// console.log( 'jsManager.getCodeForUrl(url)', url )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue