Skip to content

Commit

Permalink
WIP: permalink and pagination data as expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
lexoyo committed Jun 14, 2024
1 parent a63bed2 commit cc059d5
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 192 deletions.
2 changes: 1 addition & 1 deletion 11ty-test/hosting/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pagination:
data: ds_39ihty.languages
size: 1
permalink: "{% assign var_global_6 = ds_39ihty.languages | first %}{% assign var_global_7 = var_global_6.name %}{{ var_global_7 }}"
permalink: "{% assign var_global_0 = state_iuth-9752_items | first %}{% assign var_global_1 = var_global_0.name | slugify %}{{ var_global_1 }}"

---
{% assign state_iuth-9752_pagination = pagination %}
Expand Down
2 changes: 1 addition & 1 deletion 11ty-test/storage/default/website.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"assets":[],"styles":[{"selectors":["#inue"],"style":{"padding":"10px"}}],"pages":[{"frames":[{"component":{"type":"wrapper","stylable":["background","background-color","background-image","background-repeat","background-attachment","background-position","background-size"],"attributes":{"id":"ijqc"},"components":[{"type":"text","attributes":{"id":"inue"},"components":[{"type":"textnode","content":"Insert your text here"}],"privateStates":[{"id":"innerHTML","expression":[]}]}],"nameForDataSource":"","publicStates":[{"id":"pagination","hidden":true,"label":"Pagination","expression":[{"options":{"filter":"{}"},"type":"property","propType":"field","fieldId":"languages","label":"languages","typeIds":["Language"],"dataSourceId":"ds_39ihty","kind":"list"}]},{"id":"items","hidden":true,"label":"pagination.items","expression":[{"label":"Unused items label","type":"property","propType":"field","fieldId":"languages","dataSourceId":"ds_39ihty","typeIds":["languages"],"kind":"list"}]},{"id":"pages","hidden":true,"label":"pagination.pages","expression":[{"label":"Unused pages label","type":"property","propType":"field","fieldId":"languages","dataSourceId":"ds_39ihty","typeIds":["languages"],"kind":"list"}]},{"id":"eleventySeoTitle","label":"eleventySeoTitle","hidden":true,"expression":[]},{"id":"eleventySeoDescription","label":"eleventySeoDescription","hidden":true,"expression":[]},{"id":"eleventyFavicon","label":"eleventyFavicon","hidden":true,"expression":[]},{"id":"eleventyOGImage","label":"eleventyOGImage","hidden":true,"expression":[]},{"id":"eleventyOGTitle","label":"eleventyOGTitle","hidden":true,"expression":[]},{"id":"eleventyOGDescription","label":"eleventyOGDescription","hidden":true,"expression":[]},{"id":"eleventyPageData","label":"eleventyPageData","hidden":true,"expression":[{"options":{"filter":"{}"},"type":"property","propType":"field","fieldId":"continents","label":"continents","typeIds":["Continent"],"dataSourceId":"ds_39ihty","kind":"list"}]},{"id":"eleventyPermalink","label":"eleventyPermalink","hidden":true,"expression":[{"options":{},"type":"property","propType":"field","fieldId":"languages","label":"languages","typeIds":["Language"],"dataSourceId":"ds_39ihty","kind":"list"},{"type":"filter","id":"first","label":"first","options":{}},{"type":"property","propType":"field","fieldId":"name","label":"name","typeIds":["String"],"dataSourceId":"ds_39ihty","kind":"scalar","options":{}}]},{"id":"ijqc-do1nss4wml","expression":[],"label":"new-state"}],"id-plugin-data-source":"iuth-9752"},"id":"wtYFTcqmbTsXKu7q"}],"type":"main","id":"tE76lAVWbNKM7r8s","settings":{"eleventyPageSize":"1","eleventyPageData":"[{\"options\":{\"filter\":\"{}\"},\"type\":\"property\",\"propType\":\"field\",\"fieldId\":\"languages\",\"label\":\"languages\",\"typeIds\":[\"Language\"],\"dataSourceId\":\"ds_39ihty\",\"kind\":\"list\"}]","eleventyPermalink":"[{\"options\":{},\"type\":\"property\",\"propType\":\"field\",\"fieldId\":\"languages\",\"label\":\"languages\",\"typeIds\":[\"Language\"],\"dataSourceId\":\"ds_39ihty\",\"kind\":\"list\"},{\"type\":\"filter\",\"id\":\"first\",\"label\":\"first\",\"options\":{}},{\"type\":\"property\",\"propType\":\"field\",\"fieldId\":\"name\",\"label\":\"name\",\"typeIds\":[\"String\"],\"dataSourceId\":\"ds_39ihty\",\"kind\":\"scalar\",\"options\":{}}]","eleventySeoTitle":"[]","eleventySeoDescription":"[]","eleventyFavicon":"[]","eleventyOGImage":"[]","eleventyOGTitle":"[]","eleventyOGDescription":"[]","head":""}},{"name":"New page","frames":[{"component":{"type":"wrapper","stylable":["background","background-color","background-image","background-repeat","background-attachment","background-position","background-size"],"nameForDataSource":"","publicStates":[]},"id":"XWnRUJzxYZi3KkkN"}],"id":"bXBXethuIsNjUYe4N"}],"dataSources":[{"id":"ds_39ihty","label":"New data source","type":"graphql","url":"https://countries.trevorblades.com/graphql","method":"POST","headers":{"content-type":"application/json"},"readonly":false}],"settings":{"eleventyI18n":"on","eleventyFetch":"on","eleventyPageData":"[]","eleventyPermalink":"[]","eleventySeoTitle":"[]","eleventySeoDescription":"[]","eleventyFavicon":"[]","eleventyOGImage":"[]","eleventyOGTitle":"[]","eleventyOGDescription":"[]","head":""},"fonts":[],"symbols":[],"publication":{"connector":{"connectorId":"fs-hosting","type":"HOSTING","displayName":"File system hosting","icon":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M6%202L6%2022%2018%2022%2018%207%2012%202%206%202Z%22%3E%3C%2Fpath%3E%3Cpath%20d%3D%22M18%202L12%202%2012%208%2018%208%2018%202Z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E","disableLogout":true,"isLoggedIn":true,"oauthUrl":null,"color":"#ffffff","background":"#006400"}}}
{"assets":[],"styles":[],"pages":[{"name":"aaa","frames":[{"component":{"type":"wrapper","stylable":["background","background-color","background-image","background-repeat","background-attachment","background-position","background-size"],"attributes":{"id":"i77k"},"nameForDataSource":"","privateStates":[],"id-plugin-data-source":"i77k-4896","publicStates":[{"id":"pagination","hidden":true,"label":"pagination","expression":[{"label":"Unused pagination label","type":"property","propType":"field","fieldId":"pagination","dataSourceId":"eleventy","typeIds":["pagination"],"kind":"object"}]},{"id":"items","hidden":true,"label":"pagination.items","expression":[{"label":"Unused items label","type":"property","propType":"field","fieldId":"continents","dataSourceId":"ds_39ihty","typeIds":["continents"],"kind":"list"}]},{"id":"pages","hidden":true,"label":"pagination.pages","expression":[{"label":"Unused pages label","type":"property","propType":"field","fieldId":"continents","dataSourceId":"ds_39ihty","typeIds":["continents"],"kind":"list"}]},{"id":"eleventySeoTitle","label":"eleventySeoTitle","hidden":true,"expression":[]},{"id":"eleventySeoDescription","label":"eleventySeoDescription","hidden":true,"expression":[]},{"id":"eleventyFavicon","label":"eleventyFavicon","hidden":true,"expression":[]},{"id":"eleventyOGImage","label":"eleventyOGImage","hidden":true,"expression":[]},{"id":"eleventyOGTitle","label":"eleventyOGTitle","hidden":true,"expression":[]},{"id":"eleventyOGDescription","label":"eleventyOGDescription","hidden":true,"expression":[]},{"id":"eleventyPageData","label":"eleventyPageData","hidden":true,"expression":[{"options":{},"type":"property","propType":"field","fieldId":"continents","label":"continents","typeIds":["Continent"],"dataSourceId":"ds_39ihty","kind":"list"}]},{"id":"eleventyPermalink","label":"eleventyPermalink","hidden":true,"expression":[]}]},"id":"XWnRUJzxYZi3KkkN"}],"id":"bXBXethuIsNjUYe4N","settings":{"name":"aaa","eleventyPageSize":"122","eleventyPageReverse":"on","eleventyPageData":"[{\"options\":{},\"type\":\"property\",\"propType\":\"field\",\"fieldId\":\"continents\",\"label\":\"continents\",\"typeIds\":[\"Continent\"],\"dataSourceId\":\"ds_39ihty\",\"kind\":\"list\"}]","eleventyPermalink":"[{\"type\":\"state\",\"storedStateId\":\"items\",\"label\":\"pagination.items\",\"componentId\":\"i77k-4896\",\"exposed\":true},{\"type\":\"filter\",\"id\":\"first\",\"label\":\"first\",\"options\":{}},{\"type\":\"property\",\"propType\":\"field\",\"fieldId\":\"name\",\"label\":\"name\",\"typeIds\":[\"String\"],\"dataSourceId\":\"ds_39ihty\",\"kind\":\"scalar\",\"options\":{}},{\"type\":\"filter\",\"id\":\"slugify\",\"label\":\"slugify (11ty)\",\"options\":{}},{\"type\":\"filter\",\"id\":\"prepend\",\"label\":\"prepend\",\"options\":{\"value\":\"[{\\\"type\\\":\\\"property\\\",\\\"propType\\\":\\\"field\\\",\\\"fieldId\\\":\\\"fixed\\\",\\\"label\\\":\\\"Fixed value\\\",\\\"kind\\\":\\\"scalar\\\",\\\"typeIds\\\":[\\\"String\\\"],\\\"options\\\":{\\\"value\\\":\\\"/test/\\\"}}]\"}},{\"type\":\"filter\",\"id\":\"append\",\"label\":\"append\",\"options\":{\"value\":\"[{\\\"type\\\":\\\"property\\\",\\\"propType\\\":\\\"field\\\",\\\"fieldId\\\":\\\"fixed\\\",\\\"label\\\":\\\"Fixed value\\\",\\\"kind\\\":\\\"scalar\\\",\\\"typeIds\\\":[\\\"String\\\"],\\\"options\\\":{\\\"value\\\":\\\"/index.html\\\"}}]\"}}]","eleventySeoTitle":"[]","eleventySeoDescription":"[]","eleventyFavicon":"[]","eleventyOGImage":"[]","eleventyOGTitle":"[]","eleventyOGDescription":"[]","head":""},"type":"main"}],"dataSources":[{"id":"ds_39ihty","label":"New data source","type":"graphql","url":"https://countries.trevorblades.com/graphql","method":"POST","headers":{"content-type":"application/json"},"readonly":false}],"settings":{"eleventyI18n":"on","eleventyFetch":"on","eleventyPageData":"[]","eleventyPermalink":"[]","eleventySeoTitle":"[]","eleventySeoDescription":"[]","eleventyFavicon":"[]","eleventyOGImage":"[]","eleventyOGTitle":"[]","eleventyOGDescription":"[]","head":""},"fonts":[],"symbols":[],"publication":{"connector":{"connectorId":"fs-hosting","type":"HOSTING","displayName":"File system hosting","icon":"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M6%202L6%2022%2018%2022%2018%207%2012%202%206%202Z%22%3E%3C%2Fpath%3E%3Cpath%20d%3D%22M18%202L12%202%2012%208%2018%208%2018%202Z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E","disableLogout":true,"isLoggedIn":true,"oauthUrl":null,"color":"#ffffff","background":"#006400"}}}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# docker build -t linter .
# docker run -v `pwd`/src:/silex/src --rm linter
FROM node:lts

COPY . /silex
Expand Down
70 changes: 35 additions & 35 deletions src/client/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,186 +73,186 @@ class EleventyDataSource extends Backbone.Model<EleventyPluginOptions> implement
fields: [],
}, {
id: 'page',
label: 'Page',
label: 'page',
dataSourceId: 'eleventy',
fields: [{
id: 'url',
label: 'Url',
label: 'url',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'fileSlug',
label: 'File slug',
label: 'fileSlug',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'filePathStem',
label: 'File path stem',
label: 'filePathStem',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'date',
label: 'Date',
label: 'date',
typeIds: ['date'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'inputPath',
label: 'Input path',
label: 'inputPath',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'outputPath',
label: 'Output path',
label: 'outputPath',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'outputFileExtension',
label: 'Output file extension',
label: 'outputFileExtension',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'lang',
label: 'Lang',
label: 'lang',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}],
}, {
id: 'pagination',
label: 'Pagination',
label: 'pagination',
dataSourceId: 'eleventy',
fields: [{
id: 'hrefs',
label: 'Hrefs',
label: 'hrefs',
typeIds: ['string'],
kind: 'list',
dataSourceId: 'eleventy',
}, {
id: 'href',
label: 'Href',
label: 'href',
typeIds: ['paginationHref'],
kind: 'object',
dataSourceId: 'eleventy',
}, {
id: 'pageNumber',
label: 'Page number',
label: 'pageNumber',
typeIds: ['number'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'pages',
label: 'Pages',
label: 'pages',
typeIds: ['page'],
kind: 'list',
dataSourceId: 'eleventy',
}],
}, {
id: 'paginationHref',
label: 'Pagination href',
label: 'paginationHref',
dataSourceId: 'eleventy',
fields: [{
id: 'next',
label: 'Next',
label: 'next',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'previous',
label: 'Previous',
label: 'previous',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'first',
label: 'First',
label: 'first',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'last',
label: 'Last',
label: 'last',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}],
}, {
id: 'eleventy',
label: 'Eleventy',
label: 'eleventy',
dataSourceId: 'eleventy',
fields: [{
id: 'version',
label: 'Version',
label: 'version',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'generator',
label: 'Generator',
label: 'generator',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'env',
label: 'Env',
label: 'env',
typeIds: ['env'],
kind: 'object',
dataSourceId: 'eleventy',
}]
}, {
id: 'env',
label: 'Env',
label: 'env',
dataSourceId: 'eleventy',
fields: [{
id: 'root',
label: 'Root',
label: 'root',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'config',
label: 'Config',
label: 'config',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'source',
label: 'Source',
label: 'source',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'runMode',
label: 'Run mode',
label: 'runMode',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}],
}, {
id: 'locale_link',
label: 'Link',
label: 'locale_link',
dataSourceId: 'eleventy',
fields: [{
id: 'url',
label: 'Url',
label: 'url',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'lang',
label: 'Lang',
label: 'lang',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
}, {
id: 'label',
label: 'Label',
label: 'label',
typeIds: ['string'],
kind: 'scalar',
dataSourceId: 'eleventy',
Expand All @@ -266,19 +266,19 @@ class EleventyDataSource extends Backbone.Model<EleventyPluginOptions> implement
getQueryables(): Field[] {
return [{
id: 'page',
label: 'Page',
label: 'page',
typeIds: ['page'],
kind: 'object',
dataSourceId: 'eleventy',
//}, {
// id: 'eleventy',
// label: 'Eleventy',
// label: 'eleventy',
// typeIds: ['eleventy'],
// kind: 'object',
// dataSourceId: 'eleventy',
//}, {
// id: 'env',
// label: 'Env',
// label: 'env',
// typeIds: ['env'],
// kind: 'object',
// dataSourceId: 'eleventy',
Expand Down
8 changes: 4 additions & 4 deletions src/client/liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function echoBlock(component: Component, expression: Expression): string
/**
* Generate liquid instructions which echo the value of an expression, on 1 line
*/
export function echoBlock1line(component: Component | null | undefined, expression: Expression): string {
export function echoBlock1line(component: Component, expression: Expression): string {
if (expression.length === 0) throw new Error('Expression is empty')
if (expression.length === 1 && expression[0].type === 'property' && expression[0].fieldId === FIXED_TOKEN_ID) {
return expression[0].options?.value as string ?? ''
Expand Down Expand Up @@ -171,7 +171,7 @@ export function getPaginationData(expression: Property[]): string {
/**
* Convert an expression to liquid code
*/
export function getLiquidBlock(component: Component | null | undefined, expression: Expression): { variableName: string, liquid: string }[] {
export function getLiquidBlock(component: Component, expression: Expression): { variableName: string, liquid: string }[] {
if (expression.length === 0) return []
const result = [] as { variableName: string, liquid: string }[]
const firstToken = expression[0]
Expand Down Expand Up @@ -199,8 +199,8 @@ export function getLiquidBlock(component: Component | null | undefined, expressi
return result
}

export function getNextVariableName(component: Component | null | undefined, numNextVar: number): string {
return `var_${component?.ccid || 'global'}_${numNextVar}`
export function getNextVariableName(component: Component, numNextVar: number): string {
return `var_${component.ccid}_${numNextVar}`
}

/**
Expand Down
Loading

0 comments on commit cc059d5

Please sign in to comment.