New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cloudcannon/reader

Package Overview
Dependencies
Maintainers
6
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudcannon/reader - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1-0

2

package.json
{
"name": "@cloudcannon/reader",
"type": "module",
"version": "1.0.0",
"version": "1.0.1-0",
"description": "Parses config, files and folder structures to create a JSON file with information about sites made with any static site generator.",

@@ -6,0 +6,0 @@ "keywords": [

@@ -307,6 +307,6 @@ # Reader

>
> Functions are are supported with `.js` or `.cjs` files. Given file path, parsed file content and an object with filters and the `buildUrl` function as arguments. The return value should be the slash-prefixed URL string.
> Functions are are supported with `.js` or `.cjs` files. Given file path, parsed file content and an object with filters, the `buildUrl` function and the `collection_config` entry as arguments. The return value should be the slash-prefixed URL string.
>
> ```javascript
> url: (filePath, content, { filters, buildUrl }) => {
> url: (filePath, content, { filters, buildUrl, collectionConfig }) => {
> if (content.permalink) {

@@ -317,4 +317,5 @@ > // Returns a lower case permalink front matter field

>
> // Falls back to processing a url string
> return buildUrl(filePath, content, '/[slug]/');
> // Falls back to processing a default url template
> // Takes filePath, content, and a collections_config entry
> return buildUrl(filePath, content, { ...collectionsConfig, url: '/[slug]/' });
> }

@@ -332,4 +333,9 @@ > ```

> - `[path]` is the full path of the file, relative to `source`.
> - `[slug]` is the filename, excluding extension.
> - `[base_path]` is the path of the file excluding filename, relative to site `source`.
> - `[slug]` is the filename, excluding extension. Is an empty string if this results in "index".
> - `[filename]` is the filename, including extension.
> - `[ext]` is the last extension, including `.`.
> - `[relative_path]` is the full path of the file, relative to the collection `path`.
> - `[relative_base_path]` is the path of the file excluding filename, relative to the collection `path`.
> - `[full_slug]` is an alias for `[relative_base_path]/[slug]`
>

@@ -336,0 +342,0 @@ > Data placeholders are populated from front matter or data values in the file, and support a number of filters:

@@ -28,3 +28,3 @@ import chalk from 'chalk';

collection: key,
url: buildUrl(itemPath, data, collectionConfig.url)
url: buildUrl(itemPath, data, collectionConfig)
};

@@ -31,0 +31,0 @@ } catch (e) {

@@ -19,10 +19,22 @@ import { parse } from 'path';

function processFileTemplates(urlTemplate, filePath) {
const { name, ext } = parse(filePath);
function processFileTemplates(urlTemplate, filePath, collectionPath) {
const { name, ext, dir: basePath, base: filename } = parse(filePath);
const slug = name === 'index' ? '' : name;
const relativePath = collectionPath
? filePath.replace(new RegExp(`^/?${collectionPath}/`), '')
: filePath;
const relativeBasePath = collectionPath
? parse(relativePath).dir || ''
: basePath;
return urlTemplate
.replace(/\[ext\]/g, ext)
.replace(/\[slug\]/g, slug)
.replace(/\[filename\]/g, slug)
.replace(/\[filename\]/g, filename)
.replace(/\[base_path\]/g, basePath)
.replace(/\[relative_path\]/g, relativePath)
.replace(/\[relative_base_path\]/g, relativeBasePath)
.replace(/\[full_slug\]/g, `${relativeBasePath}/${slug}`)
.replace(/\[path\]/g, filePath);

@@ -43,12 +55,19 @@ }

export function buildUrl(filePath, data, urlTemplate) {
if (!urlTemplate) {
export function buildUrl(filePath, data, collectionConfigOrUrl) {
const isUrl = typeof collectionConfigOrUrl === 'string'
|| typeof collectionConfigOrUrl === 'function';
const collectionConfig = isUrl
? { url: collectionConfigOrUrl }
: (collectionConfigOrUrl || {});
if (!collectionConfig.url) {
return '';
}
if (typeof urlTemplate === 'function') {
return urlTemplate(filePath, data, { filters, buildUrl });
if (typeof collectionConfig.url === 'function') {
return collectionConfig.url(filePath, data, { filters, buildUrl, collectionConfig });
}
const fileTemplated = processFileTemplates(urlTemplate, filePath);
const fileTemplated = processFileTemplates(collectionConfig.url, filePath, collectionConfig.path);
const templated = processDataTemplates(fileTemplated, data);

@@ -55,0 +74,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc