-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@dpc-sdp/nuxt-ripple): 🚧 wip on adding favicon generation as module
- Loading branch information
1 parent
1f1c21e
commit 34279a1
Showing
5 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { init as initRfgApi } from 'rfg-api' | ||
import path from 'path' | ||
|
||
const { generateFavicon, createRequest } = initRfgApi() | ||
|
||
export interface generateOpts { | ||
masterPath: string | ||
outputPath: string | ||
API_KEY: string | ||
themeColour: string | ||
} | ||
|
||
export async function generate(opt: generateOpts): Promise<object | null> { | ||
console.log('Favicon: generating assets') | ||
|
||
const iosConfig = { | ||
pictureAspect: 'noChange' | ||
} | ||
|
||
const safariConfig = { | ||
pictureAspect: 'black_and_white', | ||
backgroundColor: '#ffffff', | ||
threshold: 60 | ||
} | ||
|
||
const androidConfig = { | ||
pictureAspect: 'noChange', | ||
manifest: { | ||
name: 'Ripple', | ||
display: 'standalone', | ||
orientation: 'portrait', | ||
start_url: '/' | ||
}, | ||
assets: { | ||
legacyIcon: false, | ||
lowResolutionIcons: false | ||
}, | ||
theme_color: opt.themeColour | ||
} | ||
|
||
const windowsConfig = { | ||
pictureAspect: 'white_silhouette', | ||
backgroundColor: opt.themeColour, | ||
assets: { | ||
windows80Ie10Tile: true, | ||
windows10Ie11EdgeTiles: { | ||
small: true, | ||
medium: true, | ||
big: true, | ||
rectangle: true | ||
} | ||
} | ||
} | ||
|
||
const faviconDesign = { | ||
desktopBrowser: {}, | ||
ios: iosConfig, | ||
androidChrome: androidConfig, | ||
safariPinnedTab: safariConfig, | ||
windows: windowsConfig | ||
} | ||
|
||
return generateFavicon( | ||
createRequest({ | ||
apiKey: opt.API_KEY, | ||
masterPicture: opt.masterPath, | ||
iconsPath: opt.outputPath, | ||
design: faviconDesign, | ||
settings: { usePathAsIs: false } | ||
// versioning? | ||
}), | ||
path.resolve(process.cwd(), opt.outputPath || '.'), | ||
(err: any) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
console.log('Favicon: generate complete!') | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// `nuxt/kit` is a helper subpath import you can use when defining local modules | ||
// that means you do not need to add `@nuxt/kit` to your project's dependencies | ||
import { createResolver, defineNuxtModule } from 'nuxt/kit' | ||
import { generate } from './../lib/generate' | ||
import * as jsonapiParse from 'jsonapi-parse' | ||
|
||
export default defineNuxtModule({ | ||
meta: { | ||
name: 'generateFavicon' | ||
}, | ||
hooks: { | ||
ready: async (nuxtApp) => { | ||
console.info(`app ready`) | ||
const faviconApiKey = '' | ||
|
||
// the tide baseurl | ||
const tideBaseUrl = nuxtApp.options.runtimeConfig.public.tide.baseUrl | ||
|
||
// the public folder | ||
const publicFolderPath = nuxtApp.options.alias.public | ||
|
||
// 1. check the public folder does not already have a favicon.ico | ||
|
||
// 2. fetch the site taxonomy | ||
const siteTaxonomyRes = await fetch( | ||
`${tideBaseUrl}/api/v1/taxonomy_term/sites?filter%5Bdrupal_internal__tid%5D=8888&site=8888&include=field_site_favicon` | ||
) | ||
const siteTaxonomyData = await siteTaxonomyRes.json() | ||
const parsedData = jsonapiParse.parse(siteTaxonomyData).data | ||
|
||
// This is the favicon URL from the site taxonomy | ||
console.log('siteTaxonomy', parsedData[0]?.field_site_favicon?.url) | ||
|
||
// 3. fetch and save the favicon in the public folder nuxtApp.options.alias.public | ||
// save a reference to the saved favicon path savedFaviconPath | ||
|
||
// 4. generate the icons | ||
|
||
// https://develop.content.reference.sdp.vic.gov.au/api/v1/taxonomy_term/sites?filter%5Bdrupal_internal__tid%5D=8888&site=8888&include=field_site_favicon | ||
|
||
// await generate({ | ||
// masterPath: `${publicFolderPath}/${savedFaviconPath}`, | ||
// outputPath: publicFolderPath, | ||
// API_KEY: faviconApiKey, | ||
// themeColour: 'red' | ||
// }) | ||
} | ||
}, | ||
setup() { | ||
const { resolve } = createResolver(import.meta.url) | ||
// console.log(resolve('./../lib/generate')) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.