Understanding How Angular-Scully Plug-ins Reflect Config objects

Asked 2 years ago, Updated 2 years ago, 227 views

I'm trying to launch a blog as a static site using Angular and Scully modules.
I implemented the automatic generation of archive pages as a plug-in, but the setConfig function may not work well.

Learn how to configure plug-ins from non-plug-in scripts
I think there is something wrong, but it has not been resolved at all.
Please let me know if there is anything I should check or easily miss.

What I could do:

  • Generate html from markdown using modules for Angular, Scully, and markdown
  • Implementing archival page generation as plugin to run during "routeProcess"
  • Verify that the plugin can automatically generate archive pages divided into multiple pages

Problem:

  • For now, the config object is defined as a constant in the .ts file, which is the same as the plugin itself file.Failed to set/reflect configuration from outside
  • If possible, I would like to be able to configure the configuration such as curly.{project name}.ts
  • But I can't override the settings using setConfig

Plugin Code

import {HandledRoute, registerPlugin, RouteTypes} from "@scullyio/scully"

export const ARCHIVES_PLUGIN='archive'

export interface ArchivePluginConfig {
    root:string;
    articleRoute:string;
    archivePrefixRoute:string;
    archiveSize:number;
}

// First, define the config as a constant in the plugin file
export const EXAMPLE_CONFIGS: ArchivePluginConfig[] = [{
    root: "/blog",
    articleRoute: "/blog/articles",
    archivePrefixRoute: "/archives",
    archiveSize—8,
}];

export function archivePlugin(routes:HandledRoute[], config?:ArchivePluginConfig[]):Promise <HandledRoute[]>{
    // Undefined or check if elements exist in the array and decide whether to apply the previous configuration
    // If you use console.log(config) before running this line next time, undefined appears.
    config=(config==undefined||config.length<1) ?EXAMPLE_CONFIGS:config;

    config.forEach(config=>{       
        //add archives for blog
        let posts = routes.filter(route)=>route.route.startsWith(config.articleRoute));
        letarchiveCount=Math.floor(posts.length/config.archiveSize)+1;
        
        letarchives —HandledRoute[]=[];
        for (let page=1; page<=archiveCount;page++){
            archive.push({route:`${config.root}${config.archivePrefixRoute}/${page}`}) 
        }
        archives.forEach(element=>{
            routes.push(element);
        });
    });
    return Promise.resolve(routes);
}

registerPlugin("routeProcess", ARCHIVES_PLUGIN, archivePlugin, [ ])

scully.{myproject}.config.tscode:

import {ScullyConfig, setPluginConfig} from '@scullyio/scully';
import'./scully/plugins/archive';
import {ArchivePluginConfig, ARCHIVES_PLUGIN, archivePlugin} from'./scully/plugins/archive';

setPluginConfig('md', {enableSyntaxHighlighting:true});

conformConfig —ArchivePluginConfig[] = [
  {
    root: "/blog",
    articleRoute: "blog/article",
    archiveSize—8,
    archivePrefixRoute: "/articles",
  }
]
setPluginConfig<ArchivePluginConfig[]>(ARCHIVES_PLUGIN, 'routeProcess', archiveConfig);

const defaultPostRenderers=['seoHrefOptimise'];

export const config : ScullyConfig = {
  defaultPostRenderers,
  projectRoot: "./",
  projectName: "jl-dotnet",
  outDir: './dist/static',
  routes: {
    '/blog/article/:post':{
      type: 'contentFolder',
      post: {
        folder: "./article/blog"
      }
    },
  }
};

environment, etc.:

  • OS:windows10

  • editor:vscode

  • console:git-bash

  • nodejs:v14.16.1

  • npm:7.12.0

  • A project created about a week ago about 2021/5/4

  • Create a project from IangularCli

  • Install scullyio through npm

OS:windows10

editor:vscode

console:git-bash

nodejs —v14.16.1

npm:7.12.0

Project created about a week ago 2021/5/4

Create a project from IangularCli

Install scullyio through npm

The settings for the plug-in created by someone else are working well.
For example, the following configuration will cause syntax highlights to markdown

setPluginConfig('md', {enableSyntaxHighlighting:true});

I am writing this site with a friend, but it is difficult for two people to solve it on their own, so this is my first time posting a question.We do not have much information in Japanese on the scale itself, so please forgive us for double posting with the English version of stackoverflow.

typescript markdown angular

2022-09-30 21:56

1 Answers

Resolved

  • Remove config argument from method to register as plugin
  • Declare the config variable at the beginning of this method and replace the return value of the getConfig<> function
  • Define the interface to wrap the array and use it as a config object because the config object used for setConfig does not work in an array

Now it worked


2022-09-30 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.