Skip to content

Commit

Permalink
Touching up syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
AramZS committed Dec 1, 2021
1 parent b0f64c9 commit 12cae32
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
53 changes: 44 additions & 9 deletions .eleventy.js
Expand Up @@ -277,17 +277,22 @@ module.exports = function (eleventyConfig) {
`;
}
);
function getNProjectItem(collection, page, projectName, index, operation){
function getNProjectItem(collection, page, projectName, index, operation) {
let found = false;
let i = index;
if (projectName){
if (projectName) {
let lastPost;
while (found === false) {
lastPost = getCollectionItem(collection, page, i)
if (lastPost && lastPost.data.hasOwnProperty("project") && lastPost.data.project == projectName && !lastPost.data.hasOwnProperty('wrapup')){
lastPost = getCollectionItem(collection, page, i);
if (
lastPost &&
lastPost.data.hasOwnProperty("project") &&
lastPost.data.project == projectName &&
!lastPost.data.hasOwnProperty("wrapup")
) {
found = true;
} else {
if (!lastPost){
if (!lastPost) {
return false;
}
i = operation(i);
Expand All @@ -300,16 +305,32 @@ module.exports = function (eleventyConfig) {
}
eleventyConfig.addFilter(
"getPreviousProjectItem",
function (collection, page, project){
function (collection, page, project) {
let index = -1;
return getNProjectItem(collection, page, project, index, function(i){return i-1})
return getNProjectItem(
collection,
page,
project,
index,
function (i) {
return i - 1;
}
);
}
);
eleventyConfig.addFilter(
"getNextProjectItem",
function (collection, page, project){
function (collection, page, project) {
let index = 1;
return getNProjectItem(collection, page, project, index, function(i){return i+1})
return getNProjectItem(
collection,
page,
project,
index,
function (i) {
return i + 1;
}
);
}
);
eleventyConfig.addFilter("relproject", function (url) {
Expand Down Expand Up @@ -444,6 +465,20 @@ module.exports = function (eleventyConfig) {
inside: Prism.languages.yaml,
},
});
//console.log(Prism.languages);
Prism.languages.liquid = Prism.languages.extend("html", {
templateTag: {
pattern: /(?<=\{\%).*?(?=\%\})/g,
greedy: true,
inside: Prism.languages.javascript,
},
templateTagBoundary: {
pattern: /\{\%}?|\%\}?/g,
greedy: false,
alias: "template-tag-boundary",
},
});
Prism.languages.njk = Prism.languages.extend("liquid", {});
},
});

Expand Down
21 changes: 20 additions & 1 deletion src/_sass/syntax-highlighting.scss
@@ -1,4 +1,5 @@
@use 'base-syntax-highlighting';
@use "base-syntax-highlighting";
@use "variables";

/**
* Syntax highlighting styles
Expand Down Expand Up @@ -204,3 +205,21 @@
color: #099;
} // Literal.Number.Integer.Long
}

pre[class*="language-"] {
width: 100%;
overscroll-behavior-x: contain;
.template-tag-boundary {
color: #ec4984;
}

.tag > .tag > .punctuation,
.tag > .punctuation:last-of-type {
color: #1cf08d;
}
@media (max-width: variables.$mobile-width) {
code[class*="language-"] {
font-size: 12px;
}
}
}
2 changes: 1 addition & 1 deletion src/posts/projects/devblog/hello-day-31.md
Expand Up @@ -137,7 +137,7 @@ So no project property. The project proprty of the post is escaped into its own
So now the template calls the filter like:

{% raw %}
```liquid
```njk
{% set previousPost = collections.posts | getPreviousProjectItem(page, project) %}
{% set nextPost = collections.posts | getNextProjectItem(page, project) %}
```
Expand Down

0 comments on commit 12cae32

Please sign in to comment.