packages/optimizer/demo/simple/index.js
async function copyAndTransform(file, ampRuntimeVersion) {
  const originalHtml = await readFile(file);
  const ampFile = file.substring(1, file.length)
      .replace('.html', '.amp.html');
  const allTransformationsFile = file.substring(1, file.length)
      .replace('.html', '.all.html');
  const validTransformationsFile = file.substring(1, file.length)
      .replace('.html', '.valid.html');

  // Transform into valid optimized AMP
  ampOptimizer.setConfig({
    validAmp: true,
    verbose: true,
  });
  const validOptimizedHtml = await ampOptimizer.transformHtml(originalHtml);

  // Run all optimizations including versioned AMP runtime URLs
  ampOptimizer.setConfig({
    validAmp: false,
    verbose: true,
  });
  // The transformer needs the path to the original AMP document
  // to correctly setup AMP to canonical linking
  const optimizedHtml = await ampOptimizer.transformHtml(originalHtml, {
    ampUrl: ampFile,
    ampRuntimeVersion: ampRuntimeVersion,
  });
  writeFile(allTransformationsFile, optimizedHtml);
  writeFile(validTransformationsFile, validOptimizedHtml);
  // We change the path of the original AMP file to match the new
  // amphtml link and make the canonical link point to the transformed version.
  writeFile(ampFile, originalHtml);
}
async function copyAndTransform(file, ampRuntimeVersion) {
  const originalHtml = await readFile(file);
  const ampFile = file.substring(1, file.length)
      .replace('.html', '.amp.html');
  const allTransformationsFile = file.substring(1, file.length)
      .replace('.html', '.all.html');
  const validTransformationsFile = file.substring(1, file.length)
      .replace('.html', '.valid.html');

  // Transform into valid optimized AMP
  ampOptimizer.setConfig({
    validAmp: true,
    verbose: true,
  });
  const validOptimizedHtml = await ampOptimizer.transformHtml(originalHtml);

  // Run all optimizations including versioned AMP runtime URLs
  ampOptimizer.setConfig({
    validAmp: false,
    verbose: true,
  });
  // The transformer needs the path to the original AMP document
  // to correctly setup AMP to canonical linking
  const optimizedHtml = await ampOptimizer.transformHtml(originalHtml, {
    ampUrl: ampFile,
    ampRuntimeVersion: ampRuntimeVersion,
  });
  writeFile(allTransformationsFile, optimizedHtml);
  writeFile(validTransformationsFile, validOptimizedHtml);
  // We change the path of the original AMP file to match the new
  // amphtml link and make the canonical link point to the transformed version.
  writeFile(ampFile, originalHtml);
}
async function copyAndTransform ( file , ampRuntimeVersion ) { const originalHtml = await readFile ( file ) ; const ampFile = file . substring ( 1 , file . length ) . replace ( '.html' , '.amp.html' ) ; const allTransformationsFile = file . substring ( 1 , file . length ) . replace ( '.html' , '.all.html' ) ; const validTransformationsFile = file . substring ( 1 , file . length ) . replace ( '.html' , '.valid.html' ) ; // Transform into valid optimized AMP ampOptimizer . setConfig ( { validAmp : true , verbose : true , } ) ; const validOptimizedHtml = await ampOptimizer . transformHtml ( originalHtml ) ; // Run all optimizations including versioned AMP runtime URLs ampOptimizer . setConfig ( { validAmp : false , verbose : true , } ) ; // The transformer needs the path to the original AMP document // to correctly setup AMP to canonical linking const optimizedHtml = await ampOptimizer . transformHtml ( originalHtml , { ampUrl : ampFile , ampRuntimeVersion : ampRuntimeVersion , } ) ; writeFile ( allTransformationsFile , optimizedHtml ) ; writeFile ( validTransformationsFile , validOptimizedHtml ) ; // We change the path of the original AMP file to match the new // amphtml link and make the canonical link point to the transformed version. writeFile ( ampFile , originalHtml ) ; }
Copy original and transformed AMP file into the dist dir.
Copy original and transformed AMP file into the dist dir .