Ordered one-dimensional open channels represent the typical porous structure of two-dimensional covalent organic frameworks (COFs). Here we report a general synthetic strategy for converting these open lattice structures into ordered donor–acceptor heterojunctions. A three-component topological design scheme was explored to prepare electron-donating intermediate COFs, which upon click reaction were transformed to photoelectric COFs with segregated donor–acceptor alignments, whereas electron-accepting buckyballs were spatially confined within the nanochannels via covalent anchoring on the channel walls. The donor–acceptor heterojunctions trigger photoinduced electron transfer and allow charge separation with radical species delocalized in the π-arrays, whereas the charge separation efficiency was dependent on the buckyball content. This new donor–acceptor strategy explores both skeletons and pores of COFs for charge separation and photoenergy conversion.