Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
fix(Selectors): Update selectors to also target data- prefixed versions
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ketch committed Feb 11, 2020
1 parent d7c49b7 commit 4306d68
Show file tree
Hide file tree
Showing 3 changed files with 395 additions and 263 deletions.
19 changes: 5 additions & 14 deletions src/generateSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Types, entityTypes } from '@stencila/schema'
import globby from 'globby'

// Target output path for the file containing generated custom selector definitions
const outputPath = path.join(__dirname, 'common', 'styles', 'selectors.css')
const outputPath = path.join(__dirname, 'selectors.css')

const readSchemas = async (): Promise<string[]> => {
const paths = path.join(
Expand Down Expand Up @@ -55,7 +55,6 @@ const generateItemTypes = (): [string, string][] => {
case 'Include':
case 'InlineContent':
case 'IntegerValidator':
case 'List':
case 'ListItem':
case 'Mark':
case 'Node':
Expand All @@ -71,6 +70,8 @@ const generateItemTypes = (): [string, string][] => {
case 'TupleValidator':
case 'Variable':
return { ...types, [type]: `http://schema.stenci.la/${type}` }
case 'List':
return { ...types, [type]: `http://schema.org/Item${type}` }
default:
return { ...types, [type]: `http://schema.org/${type}` }
}
Expand All @@ -84,21 +85,13 @@ const generateSelectors = async (): Promise<void> => {

generateItemTypes().map(
([type, schemaURL]) =>
(selectors += `@custom-selector :--${type} [itemtype~='${schemaURL}'];\n`)
(selectors += `@custom-selector :--${type} [itemtype~='${schemaURL}'], [data-itemtype~='${schemaURL}'];\n`)
)

let props = ''

const itemProps = await generateItemProps()

const customProps = [
'affiliations',
'authors',
'emails',
'organizations',
'references'
]

const extraProps = [
'affiliation',
'author',
Expand All @@ -112,9 +105,7 @@ const generateSelectors = async (): Promise<void> => {
const ps = [...itemProps, ...extraProps].sort()

ps.map(p => {
props += `@custom-selector :--${p} [${
customProps.includes(p) ? 'data-' : ''
}itemprop~='${p}'];\n`
props += `@custom-selector :--${p} [itemprop~='${p}'], [data-itemprop~='${p}'];\n`
})

const doc = `/**
Expand Down
Loading

0 comments on commit 4306d68

Please sign in to comment.