Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
VitalikL authored Dec 25, 2024
2 parents 51d721b + 562ee3b commit c230fc9
Show file tree
Hide file tree
Showing 21 changed files with 423 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: find assets -mindepth 1 ! -name ".gitkeep" -exec rm -rf {} +
name: Delete global assets content
- run: aws s3 cp ./src s3://sabbath-school-resources-assets.adventech.io/ --acl "public-read" --region us-east-1 --no-progress --recursive --exclude "*" --include "**/assets/cover.png" --include "**/assets/cover-landscape.png" --include "**/assets/cover-square.png" --include "**/assets/splash.png" --include "**/assets/fonts/*.ttf"
- run: aws s3 cp ./src s3://sabbath-school-resources-assets.adventech.io/ --acl "public-read" --region us-east-1 --no-progress --recursive --exclude "*" --include "**/assets/cover.png" --include "**/assets/cover-landscape.png" --include "**/assets/cover-square.png" --include "**/assets/splash.png" --include "**/assets/logo.png" --include "**/assets/fonts/*.ttf"
name: Upload resource assets
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ jobs:
name: Deploy resources
- run: node ops/deploy/deploy-languages.js
name: Deploy languages
- run: node ops/deploy/deploy-authors.js
name: Deploy authors
- run: node ops/deploy/deploy-categories.js
name: Deploy categories
- run: aws s3 cp dist/ s3://sabbath-school`[[ "${{ inputs.branch }}" = "stage" ]] && echo '-stage'`.adventech.io --acl "public-read" --region us-east-1 --no-progress --recursive
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
82 changes: 60 additions & 22 deletions ops/deploy/deploy-authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import yaml from "js-yaml"
import fs from "fs-extra"
import { fdir } from "fdir"
import { getResourceInfo } from "./deploy-resources.js"
import { isMainModule, parseResourcePath } from "../helpers/helpers.js"
import { isMainModule, parseResourcePath, sortResourcesByPattern } from "../helpers/helpers.js"
import {
API_DIST,
SOURCE_DIR,
Expand All @@ -15,11 +15,18 @@ import {
AUTHORS_FEED_FILENAME,
AUTHORS_INFO_FILENAME,
FEED_VIEWS,
FEED_SCOPES,
FEED_SCOPES, FEED_DIRECTION,
} from "../helpers/constants.js"
import crypto from "crypto"
import { getLanguageInfo } from "./deploy-languages.js"
import picomatch from "picomatch"

let getAuthorInfo = async function (author) {
let getAuthorInfo = async function (author, full) {
const authorInfo = yaml.load(fs.readFileSync(author, "utf8"))
if (!full) {
delete authorInfo.details
delete authorInfo.links
}
return authorInfo
}

Expand All @@ -44,7 +51,7 @@ let getAllTaggedResources = async function () {
for (let resource of resources) {
try {
let resourceInfo = await getResourceInfo(`${SOURCE_DIR}/${resource}`)
if (resourceInfo.author) {
if (resourceInfo.authors) {
allTaggedResources["resources"].push(resourceInfo)
}
} catch (e) {
Expand All @@ -65,59 +72,73 @@ let processAuthors = async function () {
.sync();

const allTaggedResources = await getAllTaggedResources()
const allCategories = {}
const allAuthors = {}

for (let author of authors) {

try {
const authorInfo = await getAuthorInfo(`${SOURCE_DIR}/${author}`)
const authorInfo = await getAuthorInfo(`${SOURCE_DIR}/${author}`, true)
const authorInfoDetail = { ...authorInfo }
const authorPathInfo = parseResourcePath(`${SOURCE_DIR}/${author}`)
const languageInfo = await getLanguageInfo(authorPathInfo.language)
const authorFeed = await getAuthorFeed(`${SOURCE_DIR}/${authorPathInfo.language}/${AUTHORS_DIRNAME}/${authorPathInfo.title}/${AUTHORS_FEED_FILENAME}`)

authorInfoDetail.feed = []
authorInfoDetail.feed = {}
authorInfoDetail.feed.title = authorInfo.title
authorInfoDetail.feed.groups = []

const authorResources = allTaggedResources.resources.filter(r => r.author === authorPathInfo.title)
const authorResources = allTaggedResources.resources.filter(r => r.authors.find((a) => a.id === authorInfo.id))

authorFeed.map(g => {
authorInfoDetail.feed.push({
authorFeed.groups.map((g, index) => {
authorInfoDetail.feed.groups.push({
...g,
title: g.group,
resources: [],
author: g.author || null,
resourceIds: g.resources || [],
scope: g.scope || null,
view: g.view || FEED_VIEWS.TILE,
view: g.view || FEED_VIEWS.FOLIO,
direction: g.direction || FEED_DIRECTION.HORIZONTAL,
type: "author",
seeAll: languageInfo.feedSeeAll ?? "See All",
id: crypto.createHash("sha256").update(
`${authorPathInfo.language}-authors-${g.group}-${index}`
).digest("hex"),
})
})

for (let authorResource of authorResources) {
// name
let groupByName = authorInfoDetail.feed.find(g => g.resourceIds.indexOf(authorResource.id) >= 0)
let groupByName = authorInfoDetail.feed.groups.find(g => g.resourceIds.some(i => picomatch(i)(authorResource.id) ))

if (groupByName) {
groupByName.resources.push(authorResource)
groupByName.resources = sortResourcesByPattern(groupByName.resources, groupByName.resourceIds)
continue
}

let groupByAuthor = authorInfoDetail.feed.find(g => g.author === authorResource.author)
let groupByAuthor = authorInfoDetail.feed.groups.find(g => g.author === authorResource.author)
if (groupByAuthor) {
groupByAuthor.resources.push(authorResource)
groupByAuthor.resources = sortResourcesByPattern(groupByAuthor.resources, groupByAuthor.resourceIds)
continue
}

let groupByKind = authorInfoDetail.feed.find(g => g.kind === authorResource.kind)
let groupByKind = authorInfoDetail.feed.groups.find(g => g.kind === authorResource.kind)
if (groupByKind) {
groupByKind.resources.push(authorResource)
groupByKind.resources = sortResourcesByPattern(groupByKind.resources, groupByKind.resourceIds)
continue
}

let groupByScope = authorInfoDetail.feed.find(g => g.scope === FEED_SCOPES.RESOURCE)
let groupByScope = authorInfoDetail.feed.groups.find(g => g.scope === FEED_SCOPES.RESOURCE)
if (groupByScope) {
groupByScope.resources.push(authorResource)
groupByScope.resources = sortResourcesByPattern(groupByScope.resources, groupByScope.resourceIds)
}
}


authorInfoDetail.feed = authorInfoDetail.feed.filter(g => {
authorInfoDetail.feed.groups = authorInfoDetail.feed.groups.filter(g => {
// filter feed groups that do not have any resources or docs
return g.resources.length
}).map(g => {
Expand All @@ -133,10 +154,27 @@ let processAuthors = async function () {
return g
})

if (!allCategories[authorPathInfo.language]) {
allCategories[authorPathInfo.language] = [authorInfo]
if (!allAuthors[authorPathInfo.language]) {
allAuthors[authorPathInfo.language] = [authorInfo]
} else {
allCategories[authorPathInfo.language].push(authorInfo)
allAuthors[authorPathInfo.language].push(authorInfo)
}

if (authorInfoDetail.feed.groups.length === 1) {
authorInfoDetail.feed.groups[0].direction = FEED_DIRECTION.VERTICAL
delete authorInfoDetail.feed.groups[0].seeAll
}

for(let authorFeedGroup of authorInfoDetail.feed.groups) {
let authorFeedGroupFinal = JSON.parse(JSON.stringify(authorFeedGroup))
authorFeedGroupFinal.direction = FEED_DIRECTION.VERTICAL
delete authorFeedGroupFinal.seeAll

fs.outputFileSync(`${API_DIST}/${authorPathInfo.language}/${authorPathInfo.type}/${authorPathInfo.title}/feeds/${authorFeedGroup.id}/index.json`, JSON.stringify(authorFeedGroupFinal))

if (authorInfoDetail.feed.groups.length > 1 && authorFeedGroup["resources"].length > 10) {
authorFeedGroup["resources"] = authorFeedGroup["resources"].slice(0, 10)
}
}

fs.outputFileSync(`${API_DIST}/${authorPathInfo.language}/${authorPathInfo.type}/${authorPathInfo.title}/index.json`, JSON.stringify(authorInfoDetail))
Expand All @@ -145,8 +183,8 @@ let processAuthors = async function () {
}
}

for (let language of Object.keys(allCategories)) {
fs.outputFileSync(`${API_DIST}/${language}/${AUTHORS_DIRNAME}/index.json`, JSON.stringify(allCategories[language]))
for (let language of Object.keys(allAuthors)) {
fs.outputFileSync(`${API_DIST}/${language}/${AUTHORS_DIRNAME}/index.json`, JSON.stringify(allAuthors[language]))
}
}

Expand Down
Loading

0 comments on commit c230fc9

Please sign in to comment.