Skip to content

Commit

Permalink
remove apple-device-images submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
emiyl committed Jun 13, 2023
1 parent cac3a7d commit da8a48b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 57 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@
[submodule "emiyl-theme"]
path = emiyl-theme
url = https://github.com/emiyl/emiyl-theme
[submodule "apple-device-images"]
path = apple-device-images
url = https://github.com/emiyl/apple-device-images.git
1 change: 0 additions & 1 deletion apple-device-images
Submodule apple-device-images deleted from 9ce1a8
1 change: 1 addition & 0 deletions cache/imgArr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/.vuepress/components/deviceGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<h3>{{dev.name}}</h3>
<div :class="['flexWrapper','flexImg',dev.expanded ? 'expanded' : 'small']" style="user-select: none;">
<div>
<template v-if="dev.img.count > 0"><img v-for="i in Math.min(dev.img.count,3)" :key="i" :class="['devImage', `devImage${i}`, dev.expanded ? 'expanded' : 'small']" :src="`https://img.appledb.dev/device@preview/${dev.devices[0].replace(/\//g,'%252F')}/${i-1}${isDarkMode && dev.img.dark ? '_dark' : ''}.webp`"></template>
<template v-if="dev.img.count > 0"><img v-for="i in Math.min(dev.img.count,3)" :key="i" :class="['devImage', `devImage${i}`, dev.expanded ? 'expanded' : 'small']" :src="`https://img.appledb.dev/device@preview/${dev.img.key}/${i-1}${isDarkMode && dev.img.dark ? '_dark' : ''}.webp`"></template>
<template v-else><img :class="['devImage','devImage0', dev.expanded ? 'expanded' : 'small']" :src="`/assets/images/logo${isDarkMode ? '_dark' : ''}.webp`"></template>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/.vuepress/components/deviceGroupList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default {
if (tempTypeArr.includes(g.type)) continue
tempTypeArr.push(g.type)
firstDeviceObj[g.type] = {
identifier: g.devices[0],
key: g.img.key,
imageBool: g.img.count > 0,
dark: g.img.dark
}
Expand All @@ -111,12 +111,12 @@ export default {
}
for (const o in overrides) if (firstDeviceObj.hasOwnProperty(o))
firstDeviceObj[o].identifier = overrides[o]
firstDeviceObj[o].key = overrides[o]
var ret = {}
for (const d in firstDeviceObj) {
ret[d] = firstDeviceObj[d].imageBool ?
`https://img.appledb.dev/device@preview/${firstDeviceObj[d].identifier}/0${this.isDarkMode && firstDeviceObj[d].dark ? '_dark' : ''}.webp` :
`https://img.appledb.dev/device@preview/${firstDeviceObj[d].key}/0${this.isDarkMode && firstDeviceObj[d].dark ? '_dark' : ''}.webp` :
`/assets/images/logo${this.isDarkMode ? '_dark' : ''}.webp`
}
Expand Down
78 changes: 30 additions & 48 deletions docs/.vuepress/plugins/dynamicPages/lib/getDeviceGroups.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { path, fs } = require('@vuepress/utils')
const request = require('sync-request')

const allowedDeviceTypes = [
'iPhone',
Expand All @@ -15,40 +16,19 @@ const osArr = require('../../../json/ios')
.reverse()
.filter(x => !x.beta)

function isDir(p) {
return fs.lstatSync(p).isDirectory()
}

let imgArr = []
const appleDeviceImagesPath = path.resolve(__dirname, '../../../../../apple-device-images')
const imagePath = path.join(appleDeviceImagesPath, 'images')
fs.readdirSync(imagePath)
.filter(f => f.endsWith('.png') || isDir(path.join(imagePath, f)))
.forEach(f => {
imgArr.push({
identifier: f.replace('.png',''),
imgCount: (f.endsWith('.png')) ? 1 : -1,
dark: false,
})
})

let folderArr = imgArr.filter(x => x.imgCount < 0).filter(x => isDir(path.join(appleDeviceImagesPath, `images/${x.identifier}`)))
imgArr = imgArr.filter(x => x.imgCount > 0)

for (const i of folderArr) {
let folderImgArr = []
fs.readdirSync(path.join(appleDeviceImagesPath, `images/${i.identifier}`))
.filter(f => f.endsWith('.png'))
.forEach(file => {
folderImgArr.push(file)
})
let folderImgCount = folderImgArr.filter(x => !x.endsWith('_dark.png')).length
let darkBool = folderImgArr.filter(x => x.endsWith('_dark.png')).length > 0
imgArr.push({
identifier: i.identifier,
imgCount: folderImgCount,
dark: darkBool
})
let imgJson = []
try {
const req = request(
'GET',
'https://img.appledb.dev/main.json'
).getBody('utf8')
if (!fs.existsSync('./cache')) fs.mkdirSync('./cache')
fs.writeFileSync('./cache/imgArr.json', req)

imgJson = JSON.parse(req)
} catch {
if (fs.existsSync('./cache/imgArr.json'))
imgJson = require('../cache/imgArr.json')
}

const deviceGroups = require('../../../json/deviceGroups')
Expand Down Expand Up @@ -128,22 +108,24 @@ const deviceGroups = require('../../../json/deviceGroups')
return 0
})
.map(x => {
let imgObj = {}
let firstDeviceIdentifier = ''
for (const dev of x.devices) {
imgObj = imgArr.filter(y => y.identifier == dev)
firstDeviceIdentifier = dev
if (imgObj[0] !== undefined) break
let imgObj = {
key: 'logo',
count: 1,
dark: true
}
x.img = {}
if (imgObj.length < 1) {
x.img.count = fs.existsSync(path.join(appleDeviceImagesPath, `/images-lowres/${firstDeviceIdentifier}.png`)) ? 1 : 0
x.img.dark = false
}
else {
x.img.count = imgObj[0].imgCount
x.img.dark = imgObj[0].dark

for (const dev of x.devices) {
let findImgObj = imgJson.find(y => y.key == dev)
if (findImgObj) {
imgObj.key = dev
imgObj.count = findImgObj.count
imgObj.dark = findImgObj.dark
break
}
}

console.log(imgObj)
x.img = imgObj
return x
})

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"ghbuild": "NODE_OPTIONS=--max_old_space_size=16384 vuepress build docs"
},
"dependencies": {
"marked": "^4.0.16"
"marked": "^4.0.16",
"sync-request": "^6.1.0"
}
}

0 comments on commit da8a48b

Please sign in to comment.